1 | <?php |
---|
2 | /* |
---|
3 | * ----------------------------------------------------------------------------- |
---|
4 | * Plugin Name: Grum Plugins Classes.3 |
---|
5 | * ----------------------------------------------------------------------------- |
---|
6 | * Author : Grum |
---|
7 | * email : grum@piwigo.org |
---|
8 | * website : http://photos.grum.fr |
---|
9 | * PWG user : http://forum.piwigo.org/profile.php?id=3706 |
---|
10 | * |
---|
11 | * << May the Little SpaceFrog be with you ! >> |
---|
12 | * |
---|
13 | * ----------------------------------------------------------------------------- |
---|
14 | * |
---|
15 | * See main.inc.php for release information |
---|
16 | * |
---|
17 | * manage all the ajax requests |
---|
18 | * ----------------------------------------------------------------------------- |
---|
19 | */ |
---|
20 | |
---|
21 | define('PHPWG_ROOT_PATH',dirname(dirname(dirname(__FILE__))).'/'); |
---|
22 | |
---|
23 | /* |
---|
24 | * set ajax module in admin mode if request is used for admin interface |
---|
25 | */ |
---|
26 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
27 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct'])) |
---|
28 | { |
---|
29 | define('IN_ADMIN', true); |
---|
30 | } |
---|
31 | |
---|
32 | // the common.inc.php file loads all the main.inc.php plugins files |
---|
33 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
34 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); |
---|
35 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
36 | |
---|
37 | load_language('plugin.lang', GPC_PATH); |
---|
38 | |
---|
39 | class GPC_Ajax extends CommonPlugin |
---|
40 | { |
---|
41 | /** |
---|
42 | * constructor |
---|
43 | */ |
---|
44 | public function __construct($prefixeTable, $filelocation) |
---|
45 | { |
---|
46 | $this->setPluginName("Grum Plugin Classes"); |
---|
47 | $this->setPluginNameFiles("gpc"); |
---|
48 | parent::__construct($prefixeTable, $filelocation); |
---|
49 | |
---|
50 | $tableList=array('result_cache'); |
---|
51 | $this->setTablesList($tableList); |
---|
52 | |
---|
53 | $this->loadConfig(); |
---|
54 | $this->checkRequest(); |
---|
55 | $this->returnAjaxContent(); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * check the $_REQUEST values and set default values |
---|
60 | * |
---|
61 | */ |
---|
62 | protected function checkRequest() |
---|
63 | { |
---|
64 | global $user; |
---|
65 | |
---|
66 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
67 | |
---|
68 | // check if asked function is valid |
---|
69 | if(!( |
---|
70 | $_REQUEST['ajaxfct']=='admin.rbuilder.fillCaddie' |
---|
71 | ) |
---|
72 | ) $_REQUEST['ajaxfct']=''; |
---|
73 | |
---|
74 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct']) and !is_admin()) $_REQUEST['ajaxfct']=''; |
---|
75 | |
---|
76 | if($_REQUEST['ajaxfct']!='') |
---|
77 | { |
---|
78 | /* |
---|
79 | * check admin.makeStats.getList values |
---|
80 | */ |
---|
81 | if($_REQUEST['ajaxfct']=="admin.rbuilder.fillCaddie") |
---|
82 | { |
---|
83 | if(!isset($_REQUEST['fillMode'])) $_REQUEST['fillMode']="add"; |
---|
84 | |
---|
85 | if(!($_REQUEST['fillMode']=="add" or |
---|
86 | $_REQUEST['fillMode']=="replace")) $_REQUEST['fillMode']="add"; |
---|
87 | |
---|
88 | if(!isset($_REQUEST['requestNumber'])) $_REQUEST['ajaxfct']=""; |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | /** |
---|
95 | * return ajax content |
---|
96 | */ |
---|
97 | protected function returnAjaxContent() |
---|
98 | { |
---|
99 | $result="<p class='errors'>An error has occured</p>"; |
---|
100 | switch($_REQUEST['ajaxfct']) |
---|
101 | { |
---|
102 | case 'admin.rbuilder.fillCaddie': |
---|
103 | $result=$this->ajax_gpc_admin_rbuilderFillCaddie($_REQUEST['fillMode'], $_REQUEST['requestNumber']); |
---|
104 | break; |
---|
105 | } |
---|
106 | GPCAjax::returnResult($result); |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | /*------------------------------------------------------------------------* |
---|
112 | * |
---|
113 | * ADMIN FUNCTIONS |
---|
114 | * |
---|
115 | *----------------------------------------------------------------------- */ |
---|
116 | |
---|
117 | /** |
---|
118 | * fill the caddie with the result of the requestNumber |
---|
119 | * |
---|
120 | * @param String $fillMode : 'addCaddie' or 'replaceCaddie' |
---|
121 | * @param Integer $requestNumber : number of the request in cache |
---|
122 | * @return String : |
---|
123 | */ |
---|
124 | private function ajax_gpc_admin_rbuilderFillCaddie($mode, $requestNumber) |
---|
125 | { |
---|
126 | global $user; |
---|
127 | |
---|
128 | switch($mode) |
---|
129 | { |
---|
130 | case "replace": |
---|
131 | $sql="DELETE FROM ".CADDIE_TABLE." WHERE user_id = '".$user['id']."';"; |
---|
132 | pwg_query($sql); |
---|
133 | case "add": |
---|
134 | $sql="INSERT IGNORE INTO ".CADDIE_TABLE." |
---|
135 | SELECT '".$user['id']."', image_id |
---|
136 | FROM ".$this->tables['result_cache']." |
---|
137 | WHERE id = '$requestNumber';"; |
---|
138 | pwg_query($sql); |
---|
139 | break; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | } //class |
---|
144 | |
---|
145 | |
---|
146 | $returned=new GPC_Ajax($prefixeTable, __FILE__); |
---|
147 | ?> |
---|