capitalization fix
[phpfspot.git] / rpc.php
1 <?php
2
3 /* *************************************************************************
4  *
5  * Copyright (c) by Andreas Unterkircher, unki@netshadow.at
6  * All rights reserved
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * *************************************************************************/
23
24 require_once "phpfspot.class.php";
25
26 class PHPFSPOT_RPC {
27
28    public function __construct()
29    {
30       session_start();
31
32    } // __construct()
33
34    public function process_ajax_request()
35    {
36       require_once 'HTML/AJAX/Server.php';
37
38       $server = new HTML_AJAX_Server();
39       $server->handleRequest();
40
41       $fspot = new PHPFSPOT();
42
43       /* if no action is specified, no need to further process this
44        * function here.
45        */
46       if(!isset($_GET['action']))
47          return;
48
49       switch($_GET['action']) {
50          case 'showphoto':
51             if(isset($_GET['id']) && is_numeric($_GET['id'])) {
52                $fspot->showPhoto($_GET['id']);
53             }
54             break;
55    
56          case 'show_available_tags':
57             $fspot->getAvailableTags();
58             break;
59
60          case 'show_selected_tags':
61             $fspot->getSelectedTags();
62             break;
63
64          case 'addtag':
65             if(isset($_GET['id']) && is_numeric($_GET['id'])) {
66                $fspot->addTag($_GET['id']);
67             }
68             break;
69
70          case 'deltag':
71             if(isset($_GET['id']) && is_numeric($_GET['id'])) {
72                $fspot->delTag($_GET['id']);
73             }
74             break;
75
76          case 'reset':
77             $fspot->resetTagSearch();
78             $fspot->resetTags();
79             $fspot->resetDateSearch();
80             $fspot->resetPhotoView();
81             break;
82
83          case 'tagcondition':
84             if(isset($_GET['mode']) && in_array($_GET['mode'], Array('or', 'and'))) {
85                $fspot->setTagCondition($_GET['mode']);
86             }
87             break;
88
89          case 'show_photo_index':
90             if(isset($_GET['begin_with']) && is_numeric($_GET['begin_with'])) {
91                $_SESSION['begin_with'] = $_GET['begin_with'];
92             }
93             else {
94                unset($_SESSION['begin_with']);
95             }
96             $fspot->showPhotoIndex();
97             break;
98    
99          case 'showcredits':
100             $fspot->showCredits();
101             break;
102
103          case 'search':
104                $fspot->startSearch($_GET['for'], $_GET['sort_order'], $_GET['from'], $_GET['to']);
105             
106             if((isset($_GET['from']) && $fspot->isValidDate($_GET['from'])) &&
107                (isset($_GET['to']) && $fspot->isValidDate($_GET['to']))) {
108             }
109             else {
110                $fspot->startSearch($_GET['for'], $_GET['sort_order']);
111             }
112             break;
113
114          case 'get_export':
115             /* $_GET['mode'] will be validated by getExport() */
116             $fspot->getExport($_GET['mode']);
117             break;
118
119          case 'get_photo_to_show':
120             $fspot->getCurrentPhoto();
121             break;
122
123          case 'get_calendar_matrix':
124             if((is_numeric($_GET['year']) || !isset($_GET['year'])) &&
125                (is_numeric($_GET['month']) || !isset($_GET['month'])) &&
126                (is_numeric($_GET['day']) || !isset($_GET['day']))) {
127                $fspot->get_calendar_matrix($_GET['year'], $_GET['month'], $_GET['day']);
128             }
129             break;
130
131          case 'what_to_do':
132             print $fspot->whatToDo();
133             break;
134
135          case 'reset_slideshow':
136             print $fspot->resetSlideShow();
137             break;
138
139          case 'get_next_slideshow_img':
140             print $fspot->getNextSlideShowImage();
141             break;
142          
143          case 'get_prev_slideshow_img':
144             print $fspot->getPrevSlideShowImage();
145             break;
146
147       }
148
149    } // process_ajax_request();
150
151 } // class PHPFSPOT_RPC
152
153 $rpc = new PHPFSPOT_RPC();
154 $rpc->process_ajax_request();
155
156 ?>