issue99, search for filename and photo description
[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             print $fspot->getAvailableTags();
58             break;
59
60          case 'show_selected_tags':
61             print $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->resetNameSearch();
79             $fspot->resetTags();
80             $fspot->resetDateSearch();
81             $fspot->resetPhotoView();
82             break;
83
84          case 'tagcondition':
85             if(isset($_GET['mode']) && in_array($_GET['mode'], Array('or', 'and'))) {
86                $fspot->setTagCondition($_GET['mode']);
87             }
88             break;
89
90          case 'show_photo_index':
91             if(isset($_GET['begin_with']) && is_numeric($_GET['begin_with'])) {
92                $_SESSION['begin_with'] = $_GET['begin_with'];
93             }
94             else {
95                unset($_SESSION['begin_with']);
96             }
97             $fspot->showPhotoIndex();
98             break;
99    
100          case 'showcredits':
101             $fspot->showCredits();
102             break;
103
104          case 'search':
105             $fspot->startSearch($_GET['for']);
106             break;
107
108          case 'update_sort_order':
109             if(isset($_POST['value']) && is_string($_POST['value'])) {
110                print $fspot->updateSortOrder($_POST['value']);
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 ?>