4 * webcalendarPlugin Class
7 * This file is part of GForge.
9 * GForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * GForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 class webcalendarPlugin extends Plugin {
25 function webcalendarPlugin () {
27 $this->name = "webcalendar" ;
28 $this->text = "Webcalendar" ; // To show in the tabs, use...
29 $this->hooks[] = "user_personal_links";//to make a link to the user's personal part of the plugin
30 $this->hooks[] = "usermenu" ;
31 $this->hooks[] = "groupmenu" ; // To put into the project tabs
32 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
33 $this->hooks[] = "groupisactivecheckboxpost" ; //
34 $this->hooks[] = "userisactivecheckbox" ; // The "use ..." checkbox in user account
35 $this->hooks[] = "userisactivecheckboxpost" ; //
36 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page fro group
37 $this->hooks[] = "call_user_cal"; // to show the calendar of the user (file my/index.php line 434)
38 $this->hooks[] = "call_user_js"; // call a function when you click on webcal (file my/index.php line 434)
39 $this->hooks[] = "call_group_cal"; // to show the calendar of the group (file layout.class.php ligne 627)
40 //$this->hooks[] = "iframe_group_calendar"; // to show the calendar of the group (file ligne 627)
41 $this->hooks[] = "add_cal_user"; //add a gforge user in calendar base
42 $this->hooks[] = "del_cal_user"; //dell a gforge user in calendar base
43 $this->hooks[] = "add_cal_group"; //add a group user in calendar base
44 $this->hooks[] = "del_cal_group"; //del a gforge user in calendar base
45 $this->hooks[] = "change_cal_permission"; //change permission pour webcal user (admin or not)
46 $this->hooks[] = "change_cal_permission_default"; //change permission pour webcal user (admin or not)
47 $this->hooks[] = "change_cal_permission_auto"; //change permission pour webcal user when you modify role
48 $this->hooks[] = "add_cal_link_father"; // add a link between son and father
49 $this->hooks[] = "del_cal_link_father"; // del a link between son and father
50 $this->hooks[] = "add_cal_link_father_event"; // add a link between son and father
51 $this->hooks[] = "change_cal_password"; //change the password a webcal user
52 $this->hooks[] = "change_cal_mail"; //change the mail a webcal user
53 $this->hooks[] = "cal_link_group"; //a link to group calendar
56 function CallHook ($hookname, $params) {
57 global $use_webcalendarplugin,$G_SESSION,$HTML;
58 if ($hookname == "usermenu") {
59 $text = $this->text; // this is what shows in the tab
60 if ($G_SESSION->usesPlugin("webcalendar")) {
61 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
62 echo ' | ' . $HTML->PrintSubMenu (array ($text),
63 array (util_make_url('/plugins/webcalendar/index.php' . $param)));
65 } elseif ($hookname == "groupmenu") {
66 $group_id=$params['group'];
67 $project = &group_get_object($group_id);
68 if (!$project || !is_object($project)) {
71 if ($project->isError()) {
74 if (!$project->isProject()) {
77 if ( !$project->usesPlugin ( $this->name ) ) {
78 $params['TITLES'][]=$this->text;
79 $params['DIRS'][]=util_make_url ('/plugins/webcalendar/index2.php?type=group&group_id='.$group_id) ;
81 $params['TITLES'][]=$this->text." is [Off]";
84 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
85 } elseif ($hookname == "groupisactivecheckbox") {
86 ///Check if the group is active
87 } elseif ($hookname == "groupisactivecheckboxpost") {
88 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
89 $group_id=$params['group'];
90 $group = &group_get_object($group_id);
91 $use_webcalendarplugin = getStringFromRequest('use_webcalendarplugin');
92 if ( $use_webcalendarplugin == 1 ) {
93 $group->setPluginUse ( $this->name );
95 $group->setPluginUse ( $this->name, false );
97 } elseif ($hookname == "userisactivecheckbox") {
98 //check if user is active
99 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
100 } elseif ($hookname == "userisactivecheckboxpost") {
101 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
102 $user = $params['user'];
103 $use_webcalendarplugin = getStringFromRequest('use_webcalendarplugin');
104 if ( $use_webcalendarplugin == 1 ) {
105 $user->setPluginUse ( $this->name );
107 $user->setPluginUse ( $this->name, false );
111 echo ' <input type="CHECKBOX" name="use_webcalendarplugin" value="1" ';
112 // CHECKED OR UNCHECKED?
113 if ( $user->usesPlugin ( $this->name ) ) {
116 echo "> Use ".$this->text." Plugin";
119 } elseif ($hookname == "user_personal_links") {
120 // this displays the link in the user's profile page to it's personal webcalendar (if you want other sto access it, youll have to change the permissions in the index.php
121 $userid = $params['user_id'];
122 $user = user_get_object($userid);
123 $text = $params['text'];
124 //check if the user has the plugin activated
125 if ($user->usesPlugin($this->name)) {
127 '.util_make_link('/plugins/webcalendar/index.php?id=' . $userid . '&type=user&pluginname=' . $this->name,_('View Personal webcalendar')) .'</p>';
129 } elseif ($hookname == "project_admin_plugins") {
130 // this displays the link in the project admin options page to it's webcalendar administration
131 $group_id = $params['group_id'];
132 $group = &group_get_object($group_id);
134 if ( $group->usesPlugin ( $this->name ) ) {
135 echo util_make_link('/plugins/webcalendar/index.php?id=' . $group->getID() . '&type=admin&pluginname=' . $this->name,_('View the webcalendar Administration')) . '<br />';
139 elseif ($hookname == "call_user_cal") {
140 //my/index.php line 365
143 <div id="cal" class="tabbertab" title="WebCalendar" >
144 <table width="100%" cellspacing="0" cellpadding="0" border="0" ><tr align="center" ><td >
145 <iframe name="webcal" src="<?php echo util_make_url('/plugins/webcalendar/login.php?type=user'); ?>" border=no scrolling="yes" width="100%" height="700"></iframe>
149 function reload_webcal() {
150 frames['webcal'].location.replace('<?php echo util_make_url("/plugins/webcalendar/login.php?type=user"); ?>');
156 elseif ($hookname == "call_user_js") {
157 // my/index.php line 67
160 onclick="reload_webcal()"
163 elseif ($hookname == "add_cal_user") {
165 //user.class.php line 590
166 //admin/userlist.php line 129
167 $res = db_query_params ('SELECT user_name,user_pw,email FROM users WHERE user_id = $1',
169 $row = db_fetch_array($res);
170 $res_cal = db_query_params ('INSERT INTO webcal_user (cal_login, cal_passwd, cal_email,cal_firstname, cal_is_admin) VALUES ($1,$2,$3,$4,$5)',
171 array ($row['user_name'] ,
177 elseif ($hookname == "del_cal_user") {
179 //admin/userlist.php line 122
180 $res = db_query_params ('SELECT user_name,user_pw,email FROM users WHERE user_id = $1',
182 $row = db_fetch_array($res);
183 $res_cal = db_query_params ('DELETE FROM webcal_user WHERE cal_login = $1',
184 array ($row['user_name'] ));
185 db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 OR cal_assistant = $2',
186 array ($row['user_name'] ,
187 $row['user_name'] ));
188 db_query_params ('DELETE FROM webcal_entry_user WHERE cal_login = $1 ',
189 array ($row['user_name'] ));
191 elseif ($hookname == "add_cal_group") {
193 //approve_pending.php line 69,80
194 $res = db_query_params ('SELECT unix_group_name,groups.group_id,group_name,email FROM groups,users,user_group WHERE groups.group_id = $1 AND groups.group_id = user_group.group_id AND user_group.user_id = users.user_id AND user_group.admin_flags = $2 ',
197 $row = db_fetch_array($res);
198 $res_cal = db_query_params ('INSERT INTO webcal_user (cal_login, cal_passwd, cal_firstname,cal_email) VALUES ($1,$2,$3,$4)',
199 array ($row['unix_group_name'] ,
201 addslashes($row['group_name']) ,
206 elseif ($hookname == "del_cal_group") {
208 //approve_pending.php line 90
209 $res = db_query_params ('SELECT unix_group_name,group_id,group_name FROM groups WHERE group_id = $1 ',
211 $row = db_fetch_array($res);
212 $res_cal = db_query_params ('DELETE FROM webcal_user WHERE cal_login = $1',
213 array ($row['unix_group_name'] ));
214 db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 OR cal_assistant = $2',
215 array ($row['unix_group_name'] ,
216 $row['unix_group_name'] ));
217 db_query_params ('DELETE FROM webcal_entry_user WHERE cal_login = $1 ',
218 array ($row['unix_group_name'] ));
220 elseif ($hookname == "change_cal_permission") {
221 //argument user_id -> $params[0]et group_id -> $params[1]
222 //project/admin/index.php line 72,87,103
223 //project/admin/massfinish.php line 50
228 $res = db_query_params ('SELECT value,admin_flags FROM user_group,role_setting WHERE role_setting.role_id = user_group.role_id AND user_group.user_id = $1 AND user_group.group_id = $2 AND role_setting.section_name = $3',
232 $row_flags = db_fetch_array($res);
235 $res_nom_boss = db_query_params ('SELECT unix_group_name FROM groups WHERE group_id = $1 ',
237 $row_nom_boss = db_fetch_array($res_nom_boss);
240 $res_nom_user = db_query_params ('SELECT user_name,email FROM users WHERE user_id = $1 ',
242 $row_nom_user = db_fetch_array($res_nom_user);
245 $res = db_query_params ('SELECT COUNT(*) FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
246 array ($row_nom_boss['unix_group_name'],
247 $row_nom_user['user_name']));
248 $row_num = db_fetch_array($res);
251 $res_mail = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
252 array ($row_nom_boss['unix_group_name']));
253 $row_mail = db_fetch_array($res_mail);
254 $mail = $row_mail['cal_email'] ;
258 $res_flags_admin = db_query_params ('SELECT admin_flags FROM user_group WHERE user_id = $1 AND group_id = $2',
261 $row_flags_admin = db_fetch_array($res_flags_admin);
262 if(trim($row_flags_admin['admin_flags']) == 'A' ) {
267 db_query_params ('UPDATE webcal_user SET cal_is_admin = $1 WHERE cal_login = $2',
269 $row_nom_user['user_name']));
272 if(($row_num[0] != 1 ) && ($row_flags['value'] == 1)){
274 $res_insert = db_query_params ('INSERT INTO webcal_asst (cal_boss, cal_assistant) VALUES ($1,$2)',
275 array ($row_nom_boss['unix_group_name'],
276 $row_nom_user['user_name']));
278 //we add email of the new admin
279 $mail = str_replace($row_nom_user['email'],"",$mail);
280 $mail = str_replace(",".$row_nom_user['email'],"",$mail);
289 $mail = $mail.$virgule.$row_nom_user['email'] ;
293 //$mail = $row_mail['cal_email'].",".$row_nom_user['email'] ;
294 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
295 array (trim($mail,','),
296 $row_nom_boss['unix_group_name']));
298 elseif($row_num[0] == 1 && ($row_flags['value'] != 1)){
299 $res_del = db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
300 array ($row_nom_boss['unix_group_name'],
301 $row_nom_user['user_name']));
303 //we del email of the old admin
304 $mail = str_replace(",".$row_nom_user['email'],"",$row_mail['cal_email']) ;
305 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
307 $row_nom_boss['unix_group_name']));
310 elseif ($hookname == "change_cal_permission_default") {
311 $res = db_query_params ('SELECT admin_flags FROM user_group WHERE user_id = $1 AND group_id = $2',
314 $row_flags = db_fetch_array($res);
319 $res_nom_boss = db_query_params ('SELECT unix_group_name FROM groups WHERE group_id = $1 ',
321 $row_nom_boss = db_fetch_array($res_nom_boss);
324 $res_nom_user = db_query_params ('SELECT user_name,email FROM users WHERE user_id = $1 ',
326 $row_nom_user = db_fetch_array($res_nom_user);
328 //verif du flag sur webcal
329 $res = db_query_params ('SELECT COUNT(*) FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
330 array ($row_nom_boss['unix_group_name'],
331 $row_nom_user['user_name']));
332 $row_num = db_fetch_array($res);
335 $res_mail = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
336 array ($row_nom_boss['unix_group_name']));
337 $row_mail = db_fetch_array($res_mail);
338 $mail = $row_mail['cal_email'];
340 if(($row_num[0] != 1 ) && (trim($row_flags['admin_flags']) == 'A')){
341 //recuperer le nom du user et du group
342 $res_insert = db_query_params ('INSERT INTO webcal_asst (cal_boss, cal_assistant) VALUES ($1,$2)',
343 array ($row_nom_boss['unix_group_name'],
344 $row_nom_user['user_name']));
346 //we add email of the new admin
347 $mail = str_replace($row_nom_user['email'],"",$mail);
348 $mail = str_replace(",".$row_nom_user['email'],"",$mail);
357 $mail = $mail.$virgule.$row_nom_user['email'] ;
359 //$mail = $row_mail['cal_email'].",".$row_nom_user['email'] ;
360 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
361 array (trim($mail,','),
362 $row_nom_boss['unix_group_name']));
364 elseif($row_num[0] == 1 && (trim($row_flags['admin_flags']) != 'A')){
365 $res_del = db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
366 array ($row_nom_boss['unix_group_name'],
367 $row_nom_user['user_name']));
369 //we del email of the old admin
370 $mail = str_replace(",".$row_nom_user['email'],"",$row_mail['cal_email']) ;
371 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
373 $row_nom_boss['unix_group_name']));
377 elseif ($hookname == "change_cal_permission_auto") {
378 $res = db_query_params ('SELECT value, user_id FROM user_group,role_setting WHERE role_setting.role_id = user_group.role_id AND role_setting.section_name = $1 AND group_id = $2',
382 while( $row_flags = db_fetch_array($res)){
386 //get the group and user names
387 $res_nom_boss = db_query_params ('SELECT unix_group_name FROM groups WHERE group_id = $1 ',
389 $row_nom_boss = db_fetch_array($res_nom_boss);
392 $res_nom_user = db_query_params ('SELECT user_name,email FROM users WHERE user_id = $1 ',
393 array ($row_flags['user_id']));
394 $row_nom_user = db_fetch_array($res_nom_user);
396 //verif if the user is admin
397 $res_count = db_query_params ('SELECT COUNT(*) FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
398 array ($row_nom_boss['unix_group_name'],
399 $row_nom_user['user_name']));
400 $row_num = db_fetch_array($res_count);
403 $res_mail = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
404 array ($row_nom_boss['unix_group_name']));
405 $row_mail = db_fetch_array($res_mail);
406 $mail = $row_mail['cal_email'];
408 if(($row_num[0] != 1 ) && ($row_flags['value'] == 1)){
409 //recuperer le nom du user et du group
410 $res_insert = db_query_params ('INSERT INTO webcal_asst (cal_boss, cal_assistant) VALUES ($1,$2)',
411 array ($row_nom_boss['unix_group_name'],
412 $row_nom_user['user_name']));
414 //we add email of the new admin
415 $mail = str_replace($row_nom_user['email'],"",$mail);
416 $mail = str_replace(",".$row_nom_user['email'],"",$mail);
425 $mail = $mail.$virgule.$row_nom_user['email'] ;
427 //$mail = $row_mail['cal_email'].",".$row_nom_user['email'] ;
428 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
429 array (trim($mail,','),
430 $row_nom_boss['unix_group_name']));
432 elseif($row_num[0] == 1 && ($row_flags['value'] != 1)){
433 $res_del = db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
434 array ($row_nom_boss['unix_group_name'],
435 $row_nom_user['user_name']));
437 //we del email of the old admin
438 $mail = str_replace(",".$row_nom_user['email'],"",$row_mail['cal_email']) ;
439 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
441 $row_nom_boss['unix_group_name']));
447 elseif ($hookname == "add_cal_link_father") {
448 //argument id du fils --> $params[0], id du pere--> $params[1]
449 //plugin hierachy wait_son.php line 36
450 $res_hierarchy = db_query_params ('select p1.group_id as father_id,p1.unix_group_name as father_unix_name,p1.group_name as father_name,p2.group_id as son_id,p2.unix_group_name as son_unix_name,p2.group_name as son_name from groups as p1,groups as p2,plugin_projects_hierarchy where p1.group_id=plugin_projects_hierarchy.project_id AND plugin_projects_hierarchy.project_id = $1 and p2.group_id=plugin_projects_hierarchy.sub_project_id AND plugin_projects_hierarchy.sub_project_id = $2and plugin_projects_hierarchy.activated=$3 AND plugin_projects_hierarchy.link_type=$4',
456 while($row_hierarchy = db_fetch_array($res_hierarchy)) {
457 $res_entry = db_query_params ('SELECT cal_id FROM webcal_entry_user WHERE cal_login = $1 AND cal_status = $2',
458 array ($row_hierarchy['son_unix_name'],
461 while($row_entry = db_fetch_array($res_entry)) {
462 $res_insert_entry = db_query_params ('INSERT INTO webcal_entry_user (cal_id,cal_login,cal_status) VALUES ($1,$2,$3)',
463 array ($row_entry['cal_id'],
464 $row_hierarchy['father_unix_name'],
472 elseif ($hookname == "add_cal_link_father_event") {
473 //argument name of the son --> $params[0], id_cal--> $params[1]
474 //webcalendar/edit_entry_handler.php line 390
475 //webcalendar/approve_entry.php line 21
476 $res_nom = db_query_params ('SELECT group_id FROM groups WHERE unix_group_name = $1',
478 $row_nom = db_fetch_array($res_nom);
479 $res_pere = db_query_params ('SELECT project_id, unix_group_name FROM plugin_projects_hierarchy, groups WHERE plugin_projects_hierarchy.project_id = groups.group_id AND sub_project_id = $1 AND link_type = $2 AND activated = true',
480 array ($row_nom['group_id'],
483 $row_pere = db_fetch_array($res_pere);
484 $res_insert = db_query_params ('INSERT INTO webcal_entry_user (cal_id,cal_login,cal_status) VALUES ($1,$2,$3)',
486 $row_pere['unix_group_name'],
491 elseif ($hookname == "del_cal_link_father") {
492 //argument id son --> $params[0], id father--> $params[1]
493 //plugin hierachy wait_son.php line 36
494 $res_hierarchy = db_query_params ('select p1.group_id as father_id,p1.unix_group_name as father_unix_name,p1.group_name as father_name,p2.group_id as son_id,p2.unix_group_name as son_unix_name,p2.group_name as son_name from groups as p1,groups as p2,plugin_projects_hierarchy where p1.group_id=plugin_projects_hierarchy.project_id AND plugin_projects_hierarchy.project_id = $1 and p2.group_id=plugin_projects_hierarchy.sub_project_id AND plugin_projects_hierarchy.sub_project_id = $2and plugin_projects_hierarchy.activated=$3 AND plugin_projects_hierarchy.link_type=$4',
500 while($row_hierarchy = db_fetch_array($res_hierarchy)) {
501 $res_entry = db_query_params ('SELECT cal_id FROM webcal_entry_user WHERE cal_login = $1 ',
502 array ($row_hierarchy['son_unix_name']));
504 while($row_entry = db_fetch_array($res_entry)) {
505 $res_insert_entry = db_query_params ('DELETE FROM webcal_entry_user WHERE cal_id = $1 AND cal_login = $2',
506 array ($row_entry['cal_id'],
507 $row_hierarchy['father_unix_name']));
514 elseif ($hookname == "del_cal_link_father_event") {
515 //argument id son --> $params[0], id_cal--> $params[1]
518 elseif ($hookname == "change_cal_password") {
520 //account/change_pw.php line 79
521 $res_name = db_query_params ('SELECT user_name,user_pw,email FROM users WHERE user_id = $1',
523 $row_name = db_fetch_array($res_name);
525 $res_update = db_query_params ('UPDATE webcal_user SET cal_passwd = $1, cal_email = $2 WHERE cal_login = $3',
526 array ($row_name['user_pw'],
528 $row_name['user_name']));
531 elseif ($hookname == "change_cal_mail") {
533 //account/change_email-complete.php line 63
535 $res_name = db_query_params ('SELECT user_name,user_pw,email FROM users WHERE user_id = $1',
537 $row_name = db_fetch_array($res_name);
539 $res_old = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
540 array ($row_name['user_name']));
541 $row_old = db_fetch_array($res_old);
543 //get all the cal_login where you need to change mail
544 $res_all_mail = db_query_params ('SELECT cal_login, cal_email FROM webcal_user WHERE lower(cal_email) LIKE $1',
545 array ("%".$row_old['cal_email']."%"));
546 print $query_all_mail;
547 while($row_all_mail = db_fetch_array($res_all_mail)){
548 $mail = str_replace($row_old['cal_email'],$row_name['email'],$row_all_mail['cal_email']);
549 $res_update = db_query_params ('UPDATE webcal_user SET cal_passwd = $1, cal_email = $2 WHERE cal_login = $3',
550 array ($row_name['user_pw'],
552 $row_all_mail['cal_login']));
558 elseif ($hookname == "cal_link_group" ){
559 // www/include/project_home.php line 418
561 print '<hr size="1" />';
562 print util_make_link('/plugins/webcalendar/index2.php?type=group&group_id='.$params,_('Webcalendar'));
570 // c-file-style: "bsd"