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