3 * webcalendarPlugin Class
5 * Copyright 2006, Fabien Regnier <fabien.regnier@sogeti.com>
6 * Copyright 2006, Julien Jeany <julien.jeany@sogeti.com>
7 * Copyright 2010, Roland Mas
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 class webcalendarPlugin extends Plugin {
27 function webcalendarPlugin () {
29 $this->name = "webcalendar" ;
30 $this->text = "Webcalendar" ; // To show in the tabs, use...
31 $this->hooks[] = "user_personal_links";//to make a link to the user's personal part of the plugin
32 $this->hooks[] = "usermenu" ;
33 $this->hooks[] = "groupmenu" ; // To put into the project tabs
34 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
35 $this->hooks[] = "groupisactivecheckboxpost" ; //
36 $this->hooks[] = "userisactivecheckbox" ; // The "use ..." checkbox in user account
37 $this->hooks[] = "userisactivecheckboxpost" ; //
38 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page fro group
39 $this->hooks[] = "call_user_cal"; // to show the calendar of the user (file my/index.php line 434)
40 $this->hooks[] = "call_user_js"; // call a function when you click on webcal (file my/index.php line 434)
41 $this->hooks[] = "call_group_cal"; // to show the calendar of the group (file layout.class.php ligne 627)
42 //$this->hooks[] = "iframe_group_calendar"; // to show the calendar of the group (file ligne 627)
43 $this->hooks[] = "user_setstatus";
44 $this->hooks[] = "group_approved";
45 $this->hooks[] = "change_cal_permission"; //change permission pour webcal user (admin or not)
46 $this->hooks[] = "change_cal_permission_auto"; //change permission pour webcal user when you modify role
47 $this->hooks[] = "add_cal_link_father"; // add a link between son and father
48 $this->hooks[] = "del_cal_link_father"; // del a link between son and father
49 $this->hooks[] = "add_cal_link_father_event"; // add a link between son and father
50 $this->hooks[] = "change_cal_password"; //change the password a webcal user
51 $this->hooks[] = "change_cal_mail"; //change the mail a webcal user
52 $this->hooks[] = "cal_link_group"; //a link to group calendar
53 $this->hooks[] = "role_get";
54 $this->hooks[] = "role_normalize";
55 $this->hooks[] = "role_translate_strings";
56 $this->hooks[] = "role_has_permission";
57 $this->hooks[] = "list_roles_by_permission";
60 function CallHook ($hookname, &$params) {
61 global $use_webcalendarplugin,$G_SESSION,$HTML;
62 if ($hookname == "usermenu") {
63 $text = $this->text; // this is what shows in the tab
64 if ($G_SESSION->usesPlugin("webcalendar")) {
65 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
66 echo ' | ' . $HTML->PrintSubMenu (array ($text),
67 array (util_make_url('/plugins/webcalendar/index.php' . $param)));
69 } elseif ($hookname == "groupmenu") {
70 $group_id=$params['group'];
71 $project = &group_get_object($group_id);
72 if (!$project || !is_object($project)) {
75 if ($project->isError()) {
78 if (!$project->isProject()) {
81 if ( !$project->usesPlugin ( $this->name ) ) {
82 $params['TITLES'][]=$this->text;
83 $params['DIRS'][]=util_make_url ('/plugins/webcalendar/index2.php?type=group&group_id='.$group_id) ;
85 $params['TITLES'][]=$this->text." is [Off]";
88 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
89 } elseif ($hookname == "groupisactivecheckbox") {
90 ///Check if the group is active
91 } elseif ($hookname == "groupisactivecheckboxpost") {
92 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
93 $group_id=$params['group'];
94 $group = &group_get_object($group_id);
95 $use_webcalendarplugin = getStringFromRequest('use_webcalendarplugin');
96 if ( $use_webcalendarplugin == 1 ) {
97 $group->setPluginUse ( $this->name );
99 $group->setPluginUse ( $this->name, false );
101 } elseif ($hookname == "userisactivecheckbox") {
102 //check if user is active
103 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
104 } elseif ($hookname == "userisactivecheckboxpost") {
105 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
106 $user = $params['user'];
107 $use_webcalendarplugin = getStringFromRequest('use_webcalendarplugin');
108 if ( $use_webcalendarplugin == 1 ) {
109 $user->setPluginUse ( $this->name );
111 $user->setPluginUse ( $this->name, false );
115 echo ' <input type="CHECKBOX" name="use_webcalendarplugin" value="1" ';
116 // CHECKED OR UNCHECKED?
117 if ( $user->usesPlugin ( $this->name ) ) {
120 echo "> Use ".$this->text." Plugin";
123 } elseif ($hookname == "user_personal_links") {
124 // 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
125 $userid = $params['user_id'];
126 $user = user_get_object($userid);
127 $text = $params['text'];
128 //check if the user has the plugin activated
129 if ($user->usesPlugin($this->name)) {
131 '.util_make_link('/plugins/webcalendar/index.php?id=' . $userid . '&type=user&pluginname=' . $this->name,_('View Personal webcalendar')) .'</p>';
133 } elseif ($hookname == "project_admin_plugins") {
134 // this displays the link in the project admin options page to it's webcalendar administration
135 $group_id = $params['group_id'];
136 $group = &group_get_object($group_id);
138 if ( $group->usesPlugin ( $this->name ) ) {
139 echo util_make_link('/plugins/webcalendar/index.php?id=' . $group->getID() . '&type=admin&pluginname=' . $this->name,_('View the webcalendar Administration')) . '<br />';
143 elseif ($hookname == "call_user_cal") {
144 //my/index.php line 365
147 <div id="cal" class="tabbertab" title="WebCalendar" >
148 <table width="100%" cellspacing="0" cellpadding="0" border="0" ><tr align="center" ><td >
149 <iframe name="webcal" src="<?php echo util_make_url('/plugins/webcalendar/login.php?type=user'); ?>" border=no scrolling="yes" width="100%" height="700"></iframe>
153 function reload_webcal() {
154 frames['webcal'].location.replace('<?php echo util_make_url("/plugins/webcalendar/login.php?type=user"); ?>');
160 elseif ($hookname == "call_user_js") {
161 // my/index.php line 67
164 onclick="reload_webcal()"
166 } elseif ($hookname == "role_get") {
167 $role =& $params['role'] ;
170 $right = new PluginSpecificRoleSetting ($role,
171 'plugin_webcalendar_access') ;
172 $right->SetAllowedValues (array ('0', '1', '2')) ;
173 $right->SetDefaultValues (array ('Admin' => '1',
174 'Senior Developer' => '1',
175 'Junior Developer' => '2',
177 'Support Tech' => '2')) ;
178 } elseif ($hookname == "role_normalize") {
179 $role =& $params['role'] ;
180 $new_pa =& $params['new_pa'] ;
183 $projects = $role->getLinkedProjects() ;
184 foreach ($projects as $p) {
185 $role->normalizePermsForSection ($new_pa, 'plugin_webcalendar_access', $p->getID()) ;
188 } elseif ($hookname == "role_translate_strings") {
189 $right = new PluginSpecificRoleSetting ($role,
190 'plugin_webcalendar_access') ;
191 $right->setDescription (_('Webcalendar read access')) ;
192 $right->setValueDescriptions (array ('0' => _('No reading'),
193 '1' => _('Write access'),
194 '2' => _('Read access'))) ;
195 } elseif ($hookname == "role_has_permission") {
196 if ($params['section'] == 'plugin_webcalendar_access') {
197 switch ($params['action']) {
199 $params['result'] |= ($value >= 1) ;
202 $params['result'] |= ($value == 1) ;
206 } elseif ($hookname == "list_roles_by_permission") {
207 if ($params['section'] == 'plugin_webcalendar_access') {
208 switch ($params['action']) {
210 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
213 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val = 1') ;
218 elseif ($hookname == "user_setstatus") {
219 $user = $params['user'] ;
220 $status = $params['status'] ;
222 if ($status == 'A') {
223 $res_cal = db_query_params ('SELECT COUNT(*) FROM webcal_user WHERE cal_login=$1',
224 array ($user->getUnixName())) ;
225 $row = db_fetch_array($res);
227 db_query_params ('INSERT INTO webcal_user (cal_login, cal_passwd, cal_email,cal_firstname, cal_is_admin) VALUES ($1,$2,$3,$4,$5)',
228 array ($user->getUnixName(),
231 $user->getFirstName(),
235 db_query_params ('DELETE FROM webcal_user WHERE cal_login = $1',
236 array ($user->getUnixName()));
237 db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 OR cal_assistant = $2',
238 array ($user->getUnixName(),
239 $user->getUnixName())) ;
240 db_query_params ('DELETE FROM webcal_entry_user WHERE cal_login = $1 ',
241 array ($user->getUnixName())) ;
243 } elseif ($hookname == "group_approved") {
244 $project = group_get_object ($params['group_id']) ;
247 foreach ($project->getAdmins() as $u) {
248 $emails[] = $u->getEmail() ;
251 db_query_params ('INSERT INTO webcal_user (cal_login, cal_passwd, cal_firstname,cal_email) VALUES ($1,$2,$3,$4)',
252 array ($project->getUnixName(),
254 $project->getUnixName(),
255 implode (',', $emails)));
257 elseif ($hookname == "group_approve") {
258 $res = db_query_params ('SELECT admin_flags FROM user_group WHERE user_id = $1 AND group_id = $2',
261 $row_flags = db_fetch_array($res);
266 $res_nom_boss = db_query_params ('SELECT unix_group_name FROM groups WHERE group_id = $1 ',
268 $row_nom_boss = db_fetch_array($res_nom_boss);
271 $res_nom_user = db_query_params ('SELECT user_name,email FROM users WHERE user_id = $1 ',
273 $row_nom_user = db_fetch_array($res_nom_user);
275 //verif du flag sur webcal
276 $res = db_query_params ('SELECT COUNT(*) FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
277 array ($row_nom_boss['unix_group_name'],
278 $row_nom_user['user_name']));
279 $row_num = db_fetch_array($res);
282 $res_mail = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
283 array ($row_nom_boss['unix_group_name']));
284 $row_mail = db_fetch_array($res_mail);
285 $mail = $row_mail['cal_email'];
287 if(($row_num[0] != 1 ) && (trim($row_flags['admin_flags']) == 'A')){
288 //recuperer le nom du user et du group
289 $res_insert = db_query_params ('INSERT INTO webcal_asst (cal_boss, cal_assistant) VALUES ($1,$2)',
290 array ($row_nom_boss['unix_group_name'],
291 $row_nom_user['user_name']));
293 //we add email of the new admin
294 $mail = str_replace($row_nom_user['email'],"",$mail);
295 $mail = str_replace(",".$row_nom_user['email'],"",$mail);
304 $mail = $mail.$virgule.$row_nom_user['email'] ;
306 //$mail = $row_mail['cal_email'].",".$row_nom_user['email'] ;
307 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
308 array (trim($mail,','),
309 $row_nom_boss['unix_group_name']));
311 elseif($row_num[0] == 1 && (trim($row_flags['admin_flags']) != 'A')){
312 $res_del = db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
313 array ($row_nom_boss['unix_group_name'],
314 $row_nom_user['user_name']));
316 //we del email of the old admin
317 $mail = str_replace(",".$row_nom_user['email'],"",$row_mail['cal_email']) ;
318 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
320 $row_nom_boss['unix_group_name']));
324 elseif ($hookname == "change_cal_permission") {
325 //argument user_id -> $params[0]et project_id -> $params[1]
326 //project/admin/index.php line 72,87,103
327 //project/admin/massfinish.php line 50
329 $user_id = $params[0] ;
330 $project_id = $params[1] ;
332 $project = group_get_object ($project_id) ;
333 $user = user_get_object ($user_id) ;
336 if (forge_check_perm_for_user ($user, 'plugin_webcalendar_access', $project_id, 'write')) {
338 } elseif (forge_check_perm_for_user ($user, 'plugin_webcalendar_access', $project_id, 'read')) {
344 $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',
348 $row_flags = db_fetch_array($res);
349 $user_perm = $row_flags['value'] ;
353 $res = db_query_params ('SELECT COUNT(*) FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
354 array ($project->getUnixName(),
355 $user->getUnixName()));
356 $row_num = db_fetch_array($res);
359 $res_mail = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
360 array ($project->getUnixName()));
361 $row_mail = db_fetch_array($res_mail);
362 $mail = $row_mail['cal_email'] ;
365 if($project_id == 1){
366 $res_flags_admin = db_query_params ('SELECT admin_flags FROM user_group WHERE user_id = $1 AND group_id = $2',
369 $row_flags_admin = db_fetch_array($res_flags_admin);
370 if(trim($row_flags_admin['admin_flags']) == 'A' ) {
375 db_query_params ('UPDATE webcal_user SET cal_is_admin = $1 WHERE cal_login = $2',
377 $user->getUnixName()));
380 if(($row_num[0] != 1 ) && ($user_perm == 1)){
382 $res_insert = db_query_params ('INSERT INTO webcal_asst (cal_boss, cal_assistant) VALUES ($1,$2)',
383 array ($project->getUnixName(),
384 $user->getUnixName()));
386 //we add email of the new admin
387 $mail = str_replace($user->getEmail(),"",$mail);
388 $mail = str_replace(",".$user->getEmail(),"",$mail);
397 $mail = $mail.$virgule.$user->getEmail() ;
401 //$mail = $row_mail['cal_email'].",".$row_nom_user['email'] ;
402 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
403 array (trim($mail,','),
404 $project->getUnixName()));
406 elseif($row_num[0] == 1 && ($user_perm != 1)){
407 $res_del = db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
408 array ($project->getUnixName(),
409 $user->getUnixName()));
411 //we del email of the old admin
412 $mail = str_replace(",".$row_nom_user['email'],"",$row_mail['cal_email']) ;
413 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
415 $project->getUnixName()));
418 elseif ($hookname == "change_cal_permission_auto") {
419 $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',
423 while( $row_flags = db_fetch_array($res)){
427 //get the group and user names
428 $res_nom_boss = db_query_params ('SELECT unix_group_name FROM groups WHERE group_id = $1 ',
430 $row_nom_boss = db_fetch_array($res_nom_boss);
433 $res_nom_user = db_query_params ('SELECT user_name,email FROM users WHERE user_id = $1 ',
434 array ($row_flags['user_id']));
435 $row_nom_user = db_fetch_array($res_nom_user);
437 //verif if the user is admin
438 $res_count = db_query_params ('SELECT COUNT(*) FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
439 array ($row_nom_boss['unix_group_name'],
440 $row_nom_user['user_name']));
441 $row_num = db_fetch_array($res_count);
444 $res_mail = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
445 array ($row_nom_boss['unix_group_name']));
446 $row_mail = db_fetch_array($res_mail);
447 $mail = $row_mail['cal_email'];
449 if(($row_num[0] != 1 ) && ($row_flags['value'] == 1)){
450 //recuperer le nom du user et du group
451 $res_insert = db_query_params ('INSERT INTO webcal_asst (cal_boss, cal_assistant) VALUES ($1,$2)',
452 array ($row_nom_boss['unix_group_name'],
453 $row_nom_user['user_name']));
455 //we add email of the new admin
456 $mail = str_replace($row_nom_user['email'],"",$mail);
457 $mail = str_replace(",".$row_nom_user['email'],"",$mail);
466 $mail = $mail.$virgule.$row_nom_user['email'] ;
468 //$mail = $row_mail['cal_email'].",".$row_nom_user['email'] ;
469 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
470 array (trim($mail,','),
471 $row_nom_boss['unix_group_name']));
473 elseif($row_num[0] == 1 && ($row_flags['value'] != 1)){
474 $res_del = db_query_params ('DELETE FROM webcal_asst WHERE cal_boss = $1 AND cal_assistant = $2',
475 array ($row_nom_boss['unix_group_name'],
476 $row_nom_user['user_name']));
478 //we del email of the old admin
479 $mail = str_replace(",".$row_nom_user['email'],"",$row_mail['cal_email']) ;
480 db_query_params ('UPDATE webcal_user SET cal_email = $1 WHERE cal_login = $2',
482 $row_nom_boss['unix_group_name']));
488 elseif ($hookname == "add_cal_link_father") {
489 //argument id du fils --> $params[0], id du pere--> $params[1]
490 //plugin hierachy wait_son.php line 36
491 $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',
497 while($row_hierarchy = db_fetch_array($res_hierarchy)) {
498 $res_entry = db_query_params ('SELECT cal_id FROM webcal_entry_user WHERE cal_login = $1 AND cal_status = $2',
499 array ($row_hierarchy['son_unix_name'],
502 while($row_entry = db_fetch_array($res_entry)) {
503 $res_insert_entry = db_query_params ('INSERT INTO webcal_entry_user (cal_id,cal_login,cal_status) VALUES ($1,$2,$3)',
504 array ($row_entry['cal_id'],
505 $row_hierarchy['father_unix_name'],
513 elseif ($hookname == "add_cal_link_father_event") {
514 //argument name of the son --> $params[0], id_cal--> $params[1]
515 //webcalendar/edit_entry_handler.php line 390
516 //webcalendar/approve_entry.php line 21
517 $res_nom = db_query_params ('SELECT group_id FROM groups WHERE unix_group_name = $1',
519 $row_nom = db_fetch_array($res_nom);
520 $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',
521 array ($row_nom['group_id'],
524 $row_pere = db_fetch_array($res_pere);
525 $res_insert = db_query_params ('INSERT INTO webcal_entry_user (cal_id,cal_login,cal_status) VALUES ($1,$2,$3)',
527 $row_pere['unix_group_name'],
532 elseif ($hookname == "del_cal_link_father") {
533 //argument id son --> $params[0], id father--> $params[1]
534 //plugin hierachy wait_son.php line 36
535 $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',
541 while($row_hierarchy = db_fetch_array($res_hierarchy)) {
542 $res_entry = db_query_params ('SELECT cal_id FROM webcal_entry_user WHERE cal_login = $1 ',
543 array ($row_hierarchy['son_unix_name']));
545 while($row_entry = db_fetch_array($res_entry)) {
546 $res_insert_entry = db_query_params ('DELETE FROM webcal_entry_user WHERE cal_id = $1 AND cal_login = $2',
547 array ($row_entry['cal_id'],
548 $row_hierarchy['father_unix_name']));
555 elseif ($hookname == "del_cal_link_father_event") {
556 //argument id son --> $params[0], id_cal--> $params[1]
559 elseif ($hookname == "change_cal_password") {
561 //account/change_pw.php line 79
562 $res_name = db_query_params ('SELECT user_name,user_pw,email FROM users WHERE user_id = $1',
564 $row_name = db_fetch_array($res_name);
566 $res_update = db_query_params ('UPDATE webcal_user SET cal_passwd = $1, cal_email = $2 WHERE cal_login = $3',
567 array ($row_name['user_pw'],
569 $row_name['user_name']));
572 elseif ($hookname == "change_cal_mail") {
574 //account/change_email-complete.php line 63
576 $res_name = db_query_params ('SELECT user_name,user_pw,email FROM users WHERE user_id = $1',
578 $row_name = db_fetch_array($res_name);
580 $res_old = db_query_params ('SELECT cal_email FROM webcal_user WHERE cal_login = $1',
581 array ($row_name['user_name']));
582 $row_old = db_fetch_array($res_old);
584 //get all the cal_login where you need to change mail
585 $res_all_mail = db_query_params ('SELECT cal_login, cal_email FROM webcal_user WHERE lower(cal_email) LIKE $1',
586 array ("%".$row_old['cal_email']."%"));
587 print $query_all_mail;
588 while($row_all_mail = db_fetch_array($res_all_mail)){
589 $mail = str_replace($row_old['cal_email'],$row_name['email'],$row_all_mail['cal_email']);
590 $res_update = db_query_params ('UPDATE webcal_user SET cal_passwd = $1, cal_email = $2 WHERE cal_login = $3',
591 array ($row_name['user_pw'],
593 $row_all_mail['cal_login']));
599 elseif ($hookname == "cal_link_group" ){
600 // www/include/project_home.php line 418
602 print '<hr size="1" />';
603 print util_make_link('/plugins/webcalendar/index2.php?type=group&group_id='.$params,_('Webcalendar'));
611 // c-file-style: "bsd"