function transactionSave() { $conn = Doctrine_Manager::connection(); $session = SessionWrapper::getInstance(); # begin transaction to save try { $conn->beginTransaction(); # initial save $this->save(); # commit changes $conn->commit(); # update default userid on the companyid if ($this->isSelfRegistered() && !isEmptyString($this->getCompanyID()) && isEmptyString($this->getCompany()->getDefaultUserID())) { $this->getCompany()->setDefaultUserID($this->getID()); $this->setCreatedBy($this->getID()); $this->save(); // $this->getCompany()->save(); } # send signup notification to email for public registration if ($this->isSelfRegistered() && $this->isCompanyAdmin()) { $this->sendSignupNotification(); } # invite via email if ($this->getIsInvited() == 1) { $this->inviteViaEmail(); } # check if shift has been defined if (!isEmptyString($this->getShift())) { $shift_data = array("userid" => $this->getID(), "sessionid" => $this->getShift(), "startdate" => date('Y-m-d', strtotime($this->getDateCreated())), "status" => 1, "dateadded" => DEFAULT_DATETIME, "addedbyid" => $session->getVar('userid')); $shift = new ShiftSchedule(); $shift->processPost($shift_data); $shift->save(); /* debugMessage($shift->toArray()); debugMessage('errors are '.$shift->getErrorStackAsString()); */ } # add log to audit trail $view = new Zend_View(); $controller = $this->getController(); $url = $view->serverUrl($view->baseUrl('profile/view/id/' . encode($this->getID()))); $profiletype = 'User Profile '; $usecase = '1.3'; $module = '1'; $type = USER_CREATE; $browser = new Browser(); $audit_values = $session->getVar('browseraudit'); $audit_values['module'] = $module; $audit_values['usecase'] = $usecase; $audit_values['transactiontype'] = $type; $audit_values['status'] = "Y"; $audit_values['userid'] = $session->getVar('userid'); $audit_values['transactiondetails'] = $profiletype . " <a href='" . $url . "' class='blockanchor'>" . $this->getName() . "</a> created"; $audit_values['url'] = $url; // debugMessage($audit_values); $this->notify(new sfEvent($this, $type, $audit_values)); } catch (Exception $e) { $conn->rollback(); // debugMessage('Error is '.$e->getMessage()); throw new Exception($e->getMessage()); return false; } return true; }
function schedulecreateAction() { $session = SessionWrapper::getInstance(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); // parent::createAction(); $formvalues = $this->_getAllParams(); // debugMessage($formvalues); exit(); $formvalues['id'] = $id = decode($formvalues['id']); $status = $formvalues['status']; $old_shift = $formvalues['shift_old']; $isactive = false; $shift = new ShiftSchedule(); if (!isArrayKeyAnEmptyString('id', $formvalues)) { $shift->populate($id); $isactive = $shift->isActive(); } else { $formvalues['addedbyid'] = $session->getVar('userid'); $formvalues['dateadded'] = DEFAULT_DATETIME; } $shift->processPost($formvalues); if ($shift->hasError()) { debugMessage('errors are ' . $shift->getErrorStackAsString()); exit; $session->setVar(ERROR_MESSAGE, $shift->getErrorStackAsString()); $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE))); exit; } // exit; try { $updateshift = false; if ($status == 1) { if ($old_shift != $shift->getSessionID()) { $shift->getUser()->setShift($shift->getSessionID()); $updateshift = true; } } else { if (!isEmptyString($old_shift) && $isactive) { $shift->getUser()->setShift(NULL); $updateshift = true; } } // debugMessage($shift->toArray()); exit; $shift->save(); # update any previous shifts that could still be active when setting a new active session if ($status == 1) { $updateableshifts = $shift->getCurrentActiveShiftsForUser($shift->getUserID()); // debugMessage($updateableshifts->toArray()); if ($updateableshifts->count() > 0) { foreach ($updateableshifts as $ashift) { $ashift->setStatus(0); $ashift->save(); } } } $session->setVar(SUCCESS_MESSAGE, $this->_getParam('successmessage')); $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); //debugMessage('save error '.$e->getMessage()); $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE))); } }
function getSessionEntry($userid) { $conn = Doctrine_Manager::connection(); $query = "SELECT * FROM shiftschedule AS d where d.`userid` = '" . $userid . "' AND d.status = 1 order by d.startdate desc, d.id desc limit 1 "; // debugMessage($query); $result = $conn->fetchRow($query); if (!$result) { $shift = new ShiftSchedule(); $result = $shift->toArray(); } // debugMessage($query); return $result; }
function processattendanceAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $validshift = false; $formvalues = $this->_getAllParams(); /* $formvalues = array( "id" => "", "successmessage" => "Check-In Successfull", "datein" => "Apr 24, 2015", "timein" => "8:40 PM", "inremarks" => "", "status" => "", "userid" => "93" ); */ // debugMessage($formvalues); // exit; $id = decode($formvalues['id']); $formvalues['id'] = $id; $timesheet = new Timesheet(); $user = new UserAccount(); $user->populate($formvalues['userid']); # no shift available at all on profile // validate that user is checking into right shift if (isEmptyString($id)) { $checkindate = date('Y-m-d', strtotime($formvalues['datein'])); $checkintime = date('H:i:s', strtotime($formvalues['timein'])); $checkinfulldate = $checkindate . ' ' . $checkintime; debugMessage('checkin: ' . $checkinfulldate); // if user is already checkin, throw exception if (isCheckedIn($formvalues['userid'], $checkindate)) { $message = "Check-In failed. Active session already exists"; $session->setVar(ERROR_MESSAGE, $message); exit; } $hasshift = false; $scheduleentry = getSessionEntry($user->getID()); // debugMessage($scheduleentry); if (!isEmptyString($scheduleentry['id']) && !isEmptyString($user->getShift()) && $scheduleentry['status'] == 1) { $hasshift = true; } if ($hasshift) { $shift = new ShiftSchedule(); $shift->populate($scheduleentry['id']); // debugMessage($shift->toArray()); $validstartdate = $checkindate; $validstarttime = !isEmptyString($shift->getStartTime()) ? $shift->getStartTime() : $shift->getSession()->getStartTime(); $validfullstartdate = $validstartdate . ' ' . $validstarttime; debugMessage('startin: ' . $validfullstartdate); # compute end date and time $endtime = !isEmptyString($shift->getEndTime()) ? $shift->getEndTime() : $shift->getSession()->getEndTime(); $endday = $checkindate; $starthr = date('H', strtotime($validstarttime)); //debugMessage($starthr); $endhr = date('H', strtotime($endtime)); //debugMessage($endhr); if ($endhr < $starthr) { $nxtday = date('Y-m-d', strtotime($checkindate . " + 1 day")); $endday = $nxtday; } $validenddate = $endday; $validendtime = $endtime; $validfullenddate = $validenddate . ' ' . $validendtime; debugMessage('ending: ' . $validfullenddate); // validate start and end dates for each session $rangevalid = false; if (strtotime($checkinfulldate) >= strtotime($shift->getStartDate() . ' 00:00:00')) { $rangevalid = true; if (!isEmptyString($shift->getEndDate())) { $rangevalid = false; if (strtotime($checkinfulldate) <= strtotime($shift->getEndDate() . ' 23:00:00')) { $rangevalid = true; } } } // also check if the days of the week are in the valid range if ($rangevalid) { $todaywkno = date('w', strtotime($checkinfulldate)); // debugMessage($todaywkno); $wkdaysprofiled = $user->getDaysOfWeekArray(); // debugMessage($wkdaysprofiled); if (!isEmptyString($scheduleentry['workingdays'])) { $wkdaysprofiled = explode(',', preg_replace('!\\s+!', '', trim($scheduleentry['workingdays']))); // debugMessage($wkdaysprofiled); } if (count($wkdaysprofiled) > 0) { if (!in_array($todaywkno, $wkdaysprofiled)) { $rangevalid = false; } } } // now validate the time within the session if ($rangevalid) { if (strtotime($checkinfulldate) >= strtotime($validfullstartdate) && strtotime($checkinfulldate) < strtotime($validfullenddate)) { $validshift = true; $browser = new Browser(); $audit_values = $browser_session = array("browserdetails" => $browser->getBrowserDetailsForAudit(), "browser" => $browser->getBrowser(), "version" => $browser->getVersion(), "useragent" => $browser->getUserAgent(), "os" => $browser->getPlatform(), "ismobile" => $browser->isMobile() ? '1' : 0, "ipaddress" => $browser->getIPAddress()); $formvalues['sessionid'] = $scheduleentry['sessionid']; $formvalues['ipaddress'] = $audit_values['ipaddress']; $formvalues['browser_details'] = json_encode($audit_values); } } } } /* if(!$validshift){ debugMessage('shift fail'); } else { debugMessage('shift passed'); } debugMessage($formvalues); exit; */ if (isEmptyString($id)) { $formvalues['createdby'] = $session->getVar('userid'); if (isArrayKeyAnEmptyString('isrequest', $formvalues)) { $formvalues['isrequest'] = 0; $formvalues['status'] = 0; $formvalues['timesheetdate'] = date('Y-m-d', strtotime($formvalues['datein'])); } else { $formvalues['isrequest'] = 1; if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 2; } } } if (!isEmptyString($id)) { $timesheet->populate($id); $formvalues['lastupdatedby'] = $session->getVar('userid'); if (isArrayKeyAnEmptyString('isrequest', $formvalues)) { if (isEmptyString($timesheet->getHours())) { $timesheet->setHours($timesheet->getComputedHours()); } $formvalues['isrequest'] = 0; } else { $formvalues['isrequest'] = 1; } $validshift = true; } if ($validshift) { $timesheet->processPost($formvalues); /* debugMessage($timesheet->toArray()); debugMessage('error '.$timesheet->getErrorStackAsString()); exit(); */ if ($timesheet->hasError()) { $session->setVar(ERROR_MESSAGE, $timesheet->getErrorStackAsString()); } else { try { $timesheet->save(); $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate($this->_getParam(SUCCESS_MESSAGE))); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } } else { $message = "Check-In failed. Invalid shift or session time detected. <br/> Contact admin for resolution."; $session->setVar('contactadmin', 1); if (isAdmin() || isCompanyAdmin()) { $session->setVar('contactadmin', ''); $url = $this->view->baseUrl('config/shifts/tab/schedules/userid/' . $user->getID()); $message = 'Check-In failed. Invalid shift or session time detected. <br/> <a href="' . $url . '">Click here</a> to update schedule for ' . $user->getName(); } $session->setVar(ERROR_MESSAGE, $message); } }