Example #1
0
 /**
  * run - display template and edit data
  *
  * @access public
  */
 public function run()
 {
     $tpl = new template();
     $helper = new helper();
     $values = array('description' => '', 'dateFrom' => '', 'dateTo' => '', 'allDay' => '');
     if (isset($_POST['save']) === true) {
         if (isset($_POST['allDay']) === true) {
             $allDay = 'true';
         } else {
             $allDay = 'false';
         }
         if (isset($_POST['dateFrom']) === true && isset($_POST['timeFrom']) === true) {
             $dateFrom = $helper->date2timestamp($_POST['dateFrom'], $_POST['timeFrom']);
         }
         if (isset($_POST['dateTo']) === true && isset($_POST['timeTo']) === true) {
             $dateTo = $helper->date2timestamp($_POST['dateTo'], $_POST['timeTo']);
         }
         $values = array('description' => $_POST['description'], 'dateFrom' => $dateFrom, 'dateTo' => $dateTo, 'allDay' => $allDay);
         if ($values['description'] !== '') {
             if ($helper->validateTime($_POST['timeFrom']) === true) {
                 $this->addEvent($values);
                 $msgKey = $tpl->setNotification('SAVE_SUCCESS', 'success');
             } else {
                 $tpl->setNotification('WRONG_TIME_FORMAT', 'error');
             }
         } else {
             $tpl->setNotification('NO_DESCRIPTION', 'error');
         }
         $tpl->assign('values', $values);
     }
     $tpl->assign('helper', $helper);
     $tpl->display('calendar.addEvent');
 }
 /**
  * run - display template and edit data
  *
  * @access public
  */
 public function run()
 {
     $tpl = new template();
     $msgKey = '';
     $helper = new helper();
     if (isset($_GET['id']) === true) {
         $id = $_GET['id'];
         $row = $this->getEvent($id);
         $values = array('description' => $row['description'], 'dateFrom' => $row['dateFrom'], 'dateTo' => $row['dateTo'], 'allDay' => $row['allDay']);
         if (isset($_POST['save']) === true) {
             if (isset($_POST['allDay']) === true) {
                 $allDay = 'true';
             } else {
                 $allDay = 'false';
             }
             if (isset($_POST['dateFrom']) === true && isset($_POST['timeFrom']) === true) {
                 $dateFrom = $helper->date2timestamp($_POST['dateFrom'], $_POST['timeFrom']);
                 //						$dateFrom = ''.($helper->timestamp2date($_POST['dateFrom'],6)).' '.($_POST['timeFrom']).'';
             }
             if (isset($_POST['dateTo']) === true && isset($_POST['timeTo']) === true) {
                 $dateTo = $helper->date2timestamp($_POST['dateTo'], $_POST['timeTo']);
                 //						$dateTo = ''.($helper->timestamp2date($_POST['dateTo'],6)).' '.($_POST['timeTo']).'';
             }
             $values = array('description' => $_POST['description'], 'dateFrom' => $dateFrom, 'dateTo' => $dateTo, 'allDay' => $allDay);
             if ($values['description'] !== '') {
                 if ($helper->validateTime($_POST['timeFrom']) === true) {
                     $this->editEvent($values, $id);
                     $msgKey = 'Termin bearbeitet';
                 } else {
                     $msgKey = 'Zeit hat falsches Format hh:mm';
                 }
             } else {
                 $msgKey = 'Keine Beschreibung angegeben';
             }
         }
         $tpl->assign('values', $values);
         $tpl->assign('helper', $helper);
         $tpl->assign('info', $msgKey);
         $tpl->display('calendar.editEvent');
     } else {
         $tpl->display('general.error');
     }
 }
Example #3
0
 /**
  * run - display template and edit data
  *
  * @access public
  */
 public function run()
 {
     $tpl = new template();
     $info = '';
     //Only admins and employees
     if ($_SESSION['userdata']['role'] == 'admin' || $_SESSION['userdata']['role'] == 'employee') {
         if (isset($_GET['id']) === true) {
             $projects = new projects();
             $helper = new helper();
             $tickets = new tickets();
             $id = $_GET['id'];
             $timesheet = $this->getTimesheet($id);
             $values = array('id' => $id, 'userId' => $timesheet['userId'], 'ticket' => $timesheet['ticketId'], 'project' => $timesheet['projectId'], 'date' => $timesheet['workDate'], 'kind' => $timesheet['kind'], 'hours' => $timesheet['hours'], 'description' => $timesheet['description'], 'invoicedEmpl' => $timesheet['invoicedEmpl'], 'invoicedComp' => $timesheet['invoicedComp'], 'invoicedEmplDate' => $timesheet['invoicedEmplDate'], 'invoicedCompDate' => $timesheet['invoicedCompDate']);
             if ($_SESSION['userdata']['role'] == 'admin' || $_SESSION['userdata']['id'] == $values['userId']) {
                 if (isset($_POST['save']) === true) {
                     if (isset($_POST['tickets']) && $_POST['tickets'] != '') {
                         $temp = $_POST['tickets'];
                         $tempArr = explode('|', $temp);
                         $values['project'] = $tempArr[0];
                         $values['ticket'] = $tempArr[1];
                     }
                     if (isset($_POST['kind']) && $_POST['kind'] != '') {
                         $values['kind'] = $_POST['kind'];
                     }
                     if (isset($_POST['date']) && $_POST['date'] != '') {
                         $dateFormat = $values['date'];
                         $values['date'] = $helper->date2timestamp($_POST['date']);
                         //($helper->timestamp2date($_POST['date'], 4));
                     }
                     if (isset($_POST['hours']) && $_POST['hours'] != '') {
                         $values['hours'] = $_POST['hours'];
                     }
                     if (isset($_POST['description']) && $_POST['description'] != '') {
                         $values['description'] = $_POST['description'];
                     }
                     if (isset($_POST['invoicedEmpl']) && $_POST['invoicedEmpl'] != '') {
                         if ($_POST['invoicedEmpl'] == 'on') {
                             $values['invoicedEmpl'] = 1;
                         }
                         if (isset($_POST['invoicedEmplDate']) && $_POST['invoicedEmplDate'] != '') {
                             $values['invoicedEmplDate'] = $helper->timestamp2date($_POST['invoicedEmplDate'], 4);
                         } else {
                             $values['invoicedEmplDate'] = date("Y-m-d");
                         }
                     } else {
                         $values['invoicedEmpl'] = 0;
                         $values['invoicedEmplDate'] = '';
                     }
                     if ($_SESSION['userdata']['role'] == 'admin') {
                         if (isset($_POST['invoicedComp']) && $_POST['invoicedComp'] != '') {
                             if ($_POST['invoicedComp'] == 'on') {
                                 $values['invoicedComp'] = 1;
                             }
                             if (isset($_POST['invoicedCompDate']) && $_POST['invoicedCompDate'] != '') {
                                 $values['invoicedCompDate'] = $helper->timestamp2date($_POST['invoicedCompDate'], 4);
                             } else {
                                 $values['invoicedCompDate'] = date("Y-m-d");
                             }
                         } else {
                             $values['invoicedComp'] = 0;
                             $values['invoicedCompDate'] = '';
                         }
                     }
                     if ($values['ticket'] != '' && $values['project'] != '') {
                         if ($values['kind'] != '') {
                             if ($values['date'] != '') {
                                 if ($values['hours'] != '' && $values['hours'] > 0) {
                                     $this->updateTime($values);
                                     $tpl->setNotification('SAVE_SUCCESS', 'success');
                                     $values['description'] = $_POST['description'];
                                 } else {
                                     $tpl->setNotification('NO_HOURS', 'error');
                                 }
                             } else {
                                 $tpl->setNotification('NO_DATE', 'error');
                             }
                         } else {
                             $tpl->setNotification('NO_KIND', 'error');
                         }
                     } else {
                         $tpl->setNotification('NO_TICKET', 'error');
                     }
                 }
                 $values['date'] = $helper->timestamp2date($values['date'], 2);
                 $values['invoicedCompDate'] = $helper->timestamp2date($values['invoicedCompDate'], 2);
                 $values['invoicedEmplDate'] = $helper->timestamp2date($values['invoicedEmplDate'], 2);
                 if (isset($dateFormat)) {
                     $values['date'] = $dateFormat;
                 }
                 $tpl->assign('values', $values);
                 $tpl->assign('info', $info);
                 $tpl->assign('allProjects', $projects->getAll());
                 $tpl->assign('allTickets', $tickets->getAll());
                 $tpl->assign('kind', $this->kind);
                 $tpl->display('timesheets.editTime');
             } else {
                 $tpl->display('general.error');
             }
         } else {
             $tpl->display('general.error');
         }
     } else {
         $tpl->display('general.error');
     }
 }
 /**
  * run - display template and edit data
  *
  * @access public
  *
  */
 public function run()
 {
     $tpl = new template();
     $msgKey = '';
     if (isset($_GET['id']) === true) {
         $id = (int) $_GET['id'];
         $ticket = $this->getTicket($id);
         $editable = true;
         if (!empty($ticket)) {
             $helper = new helper();
             $file = new files();
             $user = new users();
             $comment = new comments();
             // Has the user seen this ticket already
             $read = new read();
             if (!$read->isRead('ticket', $id, $_SESSION['userdata']['id'])) {
                 $read->markAsRead('ticket', $id, $_SESSION['userdata']['id']);
             }
             //TODO New access right management...This is dumb
             if ($ticket['userId'] == $_SESSION['userdata']['id'] || $ticket['editorId'] == $_SESSION['userdata']['id'] || $ticket['editorId'] == '') {
                 $editable = true;
             }
             //Punch times
             if (isset($_POST['punchIn']) && $this->isClocked($_SESSION['userdata']['id']) != true) {
                 $this->punchIn($ticket['id']);
             } else {
                 if (isset($_POST['punchOut']) && $this->isClocked($_SESSION['userdata']['id']) == true) {
                     $this->punchOut($ticket['id']);
                 }
             }
             //Upload File
             if (isset($_POST['upload'])) {
                 if (isset($_FILES['file'])) {
                     if ($file->upload($_FILES, 'ticket', $id) !== false) {
                         $tpl->setNotification('FILE_UPLOADED', 'success');
                     } else {
                         $tpl->setNotification('ERROR_WHILE_UPLOADING', 'error');
                     }
                 } else {
                     $tpl->setNotification('NO_FILE', 'error');
                 }
             }
             //Add comment
             if (isset($_POST['comment']) === true) {
                 $mail = new mailer();
                 $values = array('text' => $_POST['text'], 'date' => date("Y-m-d H:i:s"), 'userId' => $_SESSION['userdata']['id'], 'moduleId' => $id, 'commentParent' => $_POST['father']);
                 $comment->addComment($values, 'ticket');
                 $tpl->setNotification('COMMENT_ADDED', 'success');
             }
             //Only admins
             if ($_SESSION['userdata']['role'] == 'admin') {
                 $editable = true;
                 //Delete file
                 if (isset($_GET['delFile']) === true) {
                     $file = $_GET['delFile'];
                     $upload = new fileupload();
                     $upload->initFile($file);
                     //Delete file from server
                     $upload->deleteFile($file);
                     //Delete file from db
                     $this->deleteFile($file);
                     $msgKey = 'FILE_DELETED';
                 }
                 //Delete comment
                 if (isset($_GET['delComment']) === true) {
                     $commentId = (int) $_GET['delComment'];
                     $comment->deleteComment($commentId);
                     $msgKey = 'COMMENT_DELETED';
                 }
             }
             $allHours = 0;
             $values = array('userId' => $_SESSION['userdata']['id'], 'ticket' => $id, 'date' => '', 'kind' => '', 'hours' => '', 'description' => '', 'invoicedEmpl' => '', 'invoicedComp' => '', 'invoicedEmplDate' => '', 'invoicedCompDate' => '');
             $timesheets = new timesheets();
             $ticketHours = $timesheets->getTicketHours($id);
             $tpl->assign('ticketHours', $ticketHours);
             $tpl->assign('userHours', $timesheets->getUsersTicketHours($id, $_SESSION['userdata']['id']));
             $userinfo = $user->getUser($values['userId']);
             $tpl->assign('kind', $timesheets->kind);
             $tpl->assign('userInfo', $userinfo);
             if (isset($_POST['saveTimes']) === true) {
                 if (isset($_POST['kind']) && $_POST['kind'] != '') {
                     $values['kind'] = $_POST['kind'];
                 }
                 if (isset($_POST['date']) && $_POST['date'] != '') {
                     $date = $helper->date2timestamp($_POST['date']);
                     //die($date);
                     //$values['date'] = ($helper->timestamp2date($date, 4));
                     $values['date'] = $date;
                 }
                 $values['rate'] = $userinfo['wage'];
                 if (isset($_POST['hours']) && $_POST['hours'] != '') {
                     $values['hours'] = $_POST['hours'];
                 }
                 if (isset($_POST['description']) && $_POST['description'] != '') {
                     $values['description'] = $_POST['description'];
                 }
                 if ($values['kind'] != '') {
                     if ($values['date'] != '') {
                         if ($values['hours'] != '' && $values['hours'] > 0) {
                             $timesheets->addTime($values);
                             $tpl->setNotification('TIME_SAVED', 'success');
                         } else {
                             $tpl->setNotification('NO_HOURS', 'success');
                         }
                     } else {
                         $tpl->setNotification('NO_DATE', 'error');
                     }
                 } else {
                     $tpl->setNotification('NO_KIND', 'success');
                 }
                 $tpl->assign('userId', $values['userId']);
             }
             $timesheets = new timesheets();
             $language = new language();
             $language->setModule('tickets');
             $lang = $language->readIni();
             $data = array();
             $data2 = array();
             $months = array();
             $results = $timesheets->getTicketHours($id);
             $allHours = 0;
             foreach ($results as $row) {
                 if ($row['summe']) {
                     $allHours += $row['summe'];
                 }
             }
             $tpl->assign('timesheetsAllHours', $allHours);
             $remainingHours = $ticket['planHours'] - $allHours;
             $comments = $comment->getComments('ticket', $ticket['id']);
             $files = $file->getFilesByModule('ticket', $id);
             $unreadCount = count($this->getUnreadTickets($_SESSION['userdata']['id']));
             $tpl->assign('unreadCount', $unreadCount);
             $tpl->assign('imgExtensions', array('jpg', 'jpeg', 'png', 'gif', 'psd', 'bmp', 'tif', 'thm', 'yuv'));
             $tpl->assign('ticketHistory', $this->getTicketHistory((int) $_GET['id']));
             $tpl->assign('remainingHours', $remainingHours);
             $tpl->assign('ticketPrice', $this->getTicketCost($_GET['id']));
             $tpl->assign('info', $msgKey);
             $tpl->assign('role', $_SESSION['userdata']['role']);
             $tpl->assign('ticket', $ticket);
             $tpl->assign('objTicket', $this);
             $tpl->assign('state', $this->state);
             $tpl->assign('statePlain', $this->statePlain);
             $tpl->assign('numComments', $comment->countComments('ticket', $ticket['id']));
             $tpl->assign('comments', $comments);
             $tpl->assign('editable', $editable);
             $tpl->assign('files', $files);
             $tpl->assign('numFiles', count($files));
             $tpl->assign('helper', $helper);
             $tpl->display('tickets.showTicket');
         } else {
             $tpl->display('general.error');
         }
     } else {
         $tpl->display('general.error');
     }
 }
 /**
  * run - display template and edit data
  *
  * @access public
  *
  */
 public function run()
 {
     $tpl = new template();
     $projects = new projects();
     $user = new users();
     $helper = new helper();
     $language = new language();
     $language->setModule('tickets');
     $lang = $language->readIni();
     $projects = $projects->getUserProjects("open");
     $msgKey = '';
     if (isset($_GET['id']) === true) {
         $id = (int) $_GET['id'];
     }
     $row = $this->getTicket($id);
     $values = array('id' => $row['id'], 'headline' => $row['headline'], 'type' => $row['type'], 'description' => $row['description'], 'priority' => $row['priority'], 'production' => $row['production'], 'staging' => $row['staging'], 'projectId' => $row['projectId'], 'userId' => $row['userId'], 'date' => $helper->timestamp2date($row['date'], 2), 'dateToFinish' => $helper->timestamp2date($row['dateToFinish'], 2), 'status' => $row['status'], 'browser' => $row['browser'], 'os' => $row['os'], 'resolution' => $row['resolution'], 'version' => $row['version'], 'url' => $row['url'], 'planHours' => $row['planHours'], 'dependingTicketId' => $row['dependingTicketId'], 'editFrom' => $helper->timestamp2date($row['editFrom'], 2), 'editTo' => $helper->timestamp2date($row['editTo'], 2), 'editorId' => $row['editorId'], 'userFirstname' => $row['userFirstname'], 'userLastname' => $row['userLastname']);
     //Make copy of array for comparison later)
     $oldValues = $values;
     if (!empty($row) && $values['headline'] !== null) {
         if (isset($_POST['save'])) {
             $timesheet = new timesheets();
             //Set admin inputs to old values, no need to use hidden fields
             if ($_SESSION['userdata']['role'] === 'client') {
                 $_POST['userId'] = $oldValues['userId'];
                 $_POST['editFrom'] = $oldValues['editFrom'];
                 $_POST['editTo'] = $oldValues['editTo'];
                 $_POST['editorId'] = $oldValues['editorId'];
                 $_POST['planHours'] = $oldValues['planHours'];
                 $_POST['dependingTicketId'] = $oldValues['dependingTicketId'];
             }
             if (!isset($_POST['production'])) {
                 $_POST['production'] = 0;
             } else {
                 $_POST['production'] = 1;
             }
             if (!isset($_POST['staging'])) {
                 $_POST['staging'] = 0;
             } else {
                 $_POST['staging'] = 1;
             }
             if (isset($_POST['editorId']) && count($_POST['editorId'])) {
                 $editorId = implode(',', $_POST['editorId']);
             } else {
                 $editorId = '';
             }
             $values = array('id' => $id, 'headline' => $_POST['headline'], 'type' => $_POST['type'], 'description' => $_POST['description'], 'projectId' => $_POST['project'], 'priority' => $_POST['priority'], 'editorId' => $editorId, 'staging' => $_POST['staging'], 'production' => $_POST['production'], 'date' => $helper->timestamp2date(date("Y-m-d H:i:s"), 2), 'dateToFinish' => $_POST['dateToFinish'], 'status' => $_POST['status'], 'browser' => $_POST['browser'], 'os' => $_POST['os'], 'planHours' => $_POST['planHours'], 'resolution' => $_POST['resolution'], 'version' => $_POST['version'], 'url' => $_POST['url'], 'editFrom' => $_POST['editFrom'], 'editTo' => $_POST['editTo'], 'dependingTicketId' => $_POST['dependingTicketId'], 'userFirstname' => $row['userFirstname'], 'userLastname' => $row['userLastname'], 'userId' => $row['userId']);
             if ($values['headline'] === '') {
                 $tpl->setNotification('ERROR_NO_HEADLINE', 'error');
                 $msgKey = "ERROR_NO_HEADLINE";
             } elseif ($values['description'] === '') {
                 $tpl->setNotification('ERROR_NO_DESCRIPTION', 'error');
             } else {
                 //Prepare dates for db
                 $values['date'] = $helper->date2timestamp($values['date']);
                 $values['dateToFinish'] = $helper->date2timestamp($values['dateToFinish']);
                 $values['editFrom'] = $helper->date2timestamp($values['editFrom']);
                 $values['editTo'] = $helper->date2timestamp($values['editTo']);
                 //Update Ticket
                 $this->updateTicket($values, $id);
                 //Take the old value to avoid nl character
                 $values['description'] = $_POST['description'];
                 $values['date'] = $helper->timestamp2date($values['date'], 2);
                 $values['dateToFinish'] = $helper->timestamp2date($values['dateToFinish'], 2);
                 $values['editFrom'] = $helper->timestamp2date($values['editFrom'], 2);
                 $values['editTo'] = $helper->timestamp2date($values['editTo'], 2);
                 $tpl->setNotification('EDIT_SUCCESS', 'success');
                 //						$msgKey = "TICKET_EDITED";
             }
         }
         //File upload
         if (isset($_POST['upload'])) {
             if (htmlspecialchars($_FILES['file']['name']) !== '') {
                 $upload = new fileupload();
                 $upload->initFile($_FILES['file']);
                 $tpl->assign('info', $upload->error);
                 if ($upload->error == '') {
                     // hash name on server for securty reasons
                     $newname = md5($id . time());
                     $upload->renameFile($newname);
                     if ($upload->upload() === true) {
                         $fileValues = array('encName' => $upload->file_name, 'realName' => $upload->real_name, 'date' => date("Y-m-d H:i:s"), 'ticketId' => $id, 'userId' => $_SESSION['userdata']['id']);
                         $this->addFile($fileValues);
                         $tpl->setNotification('FILE_UPLOADED', 'success');
                     } else {
                         $tpl->setNotification('ERROR_FILEUPLOAD_' . $upload->error . '', 'error');
                     }
                 } else {
                     $tpl->setNotification('ERROR_FILEUPLOAD_' . $upload->error . '', 'error');
                 }
             } else {
                 $tpl->setNotification('NO_FILE', 'error');
             }
         }
         //				var_dump($values); die();
         if (!$values['projectId']) {
             $projectId = $row['projectId'];
         } else {
             $projectId = $values['projectId'];
         }
         $tpl->assign('role', $_SESSION['userdata']['role']);
         $tpl->assign('type', $this->getType());
         $tpl->assign('info', $msgKey);
         $tpl->assign('projects', $projects);
         $available = $this->getAvailableUsersForTicket($projectId);
         $tpl->assign('availableUsers', $available);
         $tpl->assign('values', $values);
         $tpl->assign('objTickets', $this);
         $tpl->assign('helper', $helper);
         $tpl->display('tickets.editTicket');
     } else {
         $tpl->display('general.error');
     }
 }