Example #1
0
 function configEdit()
 {
     $team = $_GET['team'];
     $this->title = 'Opensource Calendar';
     $this->addYUI = 1;
     $this->addAutocomplete = 1;
     $this->onCall = 1;
     $this->menu = 'backup';
     $this->view = 'calendar/calendar';
     $this->pagetitle = 'Opensource Calendar';
     $dbh = Connection::cal_ro();
     $this->action = 'configCalendar';
     $this->next_action = 'configEdit';
     $this->caltype = 'oncall';
     $this->timeaction = 'configTime';
     $obj_assignee = new calendarConfig();
     $teamid = $obj_assignee->getTeamid($dbh, $team);
     $admingrp = $obj_assignee->getAdmingroup($dbh, $team);
     $this->is_allowed = $this->checkUserPermission($admingrp);
     $this->svn_url = __SVN_URL . "dp/oncall.txt?view=log";
     $month = isset($_REQUEST['month']) && $_REQUEST['month'] != '' ? $_REQUEST['month'] : date("m");
     $year = isset($_REQUEST['year']) && $_REQUEST['year'] != '' ? $_REQUEST['year'] : date("Y");
     $this->month = $month;
     $this->year = $year;
     $this->showTime = 1;
     $this->next_action = 'configEdit';
     $obj_cal = new calender($month, $year);
     $this->days = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
     $obj_cal->getDetails();
     $this->assignee = $obj_assignee->getConfigList($dbh, $teamid, $month, $year);
     $this->teamlist = $obj_assignee->getTeamlist($dbh);
     $this->title = 'Opensource Calendar';
     $this->addYUI = 1;
     $this->addAutocomplete = 1;
     $this->onCall = 1;
     $this->menu = 'backup';
     $this->view = 'calendar/addedit';
     $dbh = Connection::cal_rw();
     $this->caltype = 'oncall';
     $this->timeaction = 'configTime';
     $this->pagetitle = $team . " Calendar";
     $this->help = "Start&nbsp;Date|End&nbsp;Date|timezone(IN|US)|Oncall&nbsp;Type(PRI|SEC|PRIMARY|SECONDARY)|Username<br>";
     $this->help .= "Example:<br>2009-08-01|2009-08-10|US|PRI|jack<br>";
     $obj = new calendarConfig();
     $admingrp = $obj->getAdmingroup($dbh, $team);
     $this->is_allowed = $this->checkUserPermission($admingrp);
     if (!$this->is_allowed) {
         $messages = OpsContext::get('messages');
         $messages->errors[] = "You don't have sufficient privilege to <b>Edit</b> this calendar! <br>";
         return forward_to('this', 'configCalendar');
     }
     $this->invalid_crumb = 0;
     if (getenv(".bycrumb") != $_REQUEST['crumb'] && $_REQUEST['btnSubmit'] != '') {
         $this->invalid_crumb = 1;
     }
     if (!$this->invalid_crumb) {
         if ($_REQUEST['oncall']) {
             $chk_old = $obj->checkIntermediateUpdate($dbh, $_REQUEST['lockid'], 'O');
             $this->lockid = $_REQUEST['lockid'];
             $this->oncall = $_REQUEST['oncall'];
             if (!$chk_old) {
                 try {
                     $res = $obj->editConfig($dbh, $_REQUEST, $team);
                     if ($res) {
                         $obj->releaseCalendarLock($dbh, $_REQUEST['lockid']);
                         $this->done = true;
                         return redirect_to('calendar', 'configCalendar');
                     }
                 } catch (Exception $e) {
                     $messages = OpsContext::get('messages');
                     $messages->errors[] = $e->getMessage();
                 }
             } else {
                 $messages = OpsContext::get('messages');
                 $messages->errors[] = "Your update session expired/Calendar updated by other user!";
                 $obj->releaseCalendarLock($dbh, $_REQUEST['lockid']);
                 return forward_to('this', 'configCalendar');
             }
         } else {
             list($edit_userid, $time_diff, $lock_id) = $obj->checkCalendarEdit($dbh, 'O');
             if (!$edit_userid) {
                 $this->lockid = $obj->lockCalendarEdit($dbh, 'O');
                 $recs = $obj->getConfigList($dbh, $teamid);
                 $timezones = $obj->getZoneList($dbh);
                 $oncall = '';
                 foreach ($recs as $rec) {
                     $oncall .= $rec[from_dt] . "|" . $rec[to_dt] . "|" . $rec[timezone] . "|" . ($rec[oncall_type] == 1 ? "PRI" : "SEC") . "|" . $rec[username] . "\n";
                     if ($start == '' || strtotime($start) < strtotime($rec[to_dt])) {
                         $start = $rec['to_dt'];
                     }
                 }
                 $start = trim($start) == '' ? date("Y-m-d", strtotime("next Friday")) : $start;
                 $arr_dates = $obj->generateDates($start, 7);
                 foreach ($arr_dates as $adates) {
                     foreach ($timezones as $zone) {
                         $oncall .= $adates[0] . "|" . $adates[1] . "|" . $zone[name] . "|PRI|" . "\n";
                         $oncall .= $adates[0] . "|" . $adates[1] . "|" . $zone[name] . "|SEC|" . "\n";
                     }
                 }
                 $this->oncall = $oncall;
             } else {
                 $this->edituser = $edit_userid;
                 $this->lockid = $lock_id;
                 $this->usage = $this->remainingDuration($time_diff);
                 $this->duration = $this->remainingDuration($time_diff, 1);
                 $this->calendar_type = "this Calendar.";
             }
         }
     } else {
         error("INVALID Crumb");
     }
     $this->oncall_tab = " class='selected'";
 }