4bb297331abbad7bff7d38a9e2c66704f8788743
[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']) && !isset($_POST['action']))
47          return;
48
49       if(isset($_GET['action']))
50          $action = $_GET['action'];
51       if(isset($_POST['action']))
52          $action = $_POST['action'];
53
54       switch($action) {
55          case 'showphoto':
56             if(isset($_GET['id']) && is_numeric($_GET['id'])) {
57                $fspot->showPhoto($_GET['id']);
58             }
59             break;
60    
61          case 'show_available_tags':
62             print $fspot->getAvailableTags();
63             break;
64
65          case 'show_selected_tags':
66             print $fspot->getSelectedTags();
67             break;
68
69          case 'addtag':
70             if(isset($_POST['id']) && is_numeric($_POST['id'])) {
71                print $fspot->addTag($_POST['id']);
72             }
73             break;
74
75          case 'deltag':
76             if(isset($_POST['id']) && is_numeric($_POST['id'])) {
77                print $fspot->delTag($_POST['id']);
78             }
79             break;
80
81          case 'reset':
82             $fspot->resetTagSearch();
83             $fspot->resetNameSearch();
84             $fspot->resetTags();
85             $fspot->resetDateSearch();
86             $fspot->resetPhotoView();
87             break;
88
89          case 'tagcondition':
90             if(isset($_POST['mode']) && in_array($_POST['mode'], Array('or', 'and'))) {
91                print $fspot->setTagCondition($_POST['mode']);
92             }
93             break;
94
95          case 'show_photo_index':
96             if(isset($_GET['begin_with']) && is_numeric($_GET['begin_with'])) {
97                $_SESSION['begin_with'] = $_GET['begin_with'];
98             }
99             else {
100                unset($_SESSION['begin_with']);
101             }
102             $fspot->showPhotoIndex();
103             break;
104    
105          case 'showcredits':
106             $fspot->showCredits();
107             break;
108
109          case 'search':
110             print $fspot->startSearch($_GET['for']);
111             break;
112
113          case 'update_sort_order':
114             if(isset($_POST['value']) && is_string($_POST['value'])) {
115                print $fspot->updateSortOrder($_POST['value']);
116             }
117             break;
118
119          case 'get_export':
120             /* $_GET['mode'] will be validated by getExport() */
121             $fspot->getExport($_GET['mode']);
122             break;
123
124          case 'get_photo_to_show':
125             $fspot->getCurrentPhoto();
126             break;
127
128          case 'get_calendar_matrix':
129             if((is_numeric($_GET['year']) || !isset($_GET['year'])) &&
130                (is_numeric($_GET['month']) || !isset($_GET['month'])) &&
131                (is_numeric($_GET['day']) || !isset($_GET['day']))) {
132                $fspot->get_calendar_matrix($_GET['year'], $_GET['month'], $_GET['day']);
133             }
134             break;
135
136          case 'what_to_do':
137             print $fspot->whatToDo();
138             break;
139
140          case 'reset_slideshow':
141             print $fspot->resetSlideShow();
142             break;
143
144          case 'get_next_slideshow_img':
145             print $fspot->getNextSlideShowImage();
146             break;
147          
148          case 'get_prev_slideshow_img':
149             print $fspot->getPrevSlideShowImage();
150             break;
151
152       }
153
154    } // process_ajax_request();
155
156 } // class PHPFSPOT_RPC
157
158 $rpc = new PHPFSPOT_RPC();
159 $rpc->process_ajax_request();
160
161 ?>