Exemplo n.º 1
0
 function processinviteAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $formvalues = $this->_getAllParams();
     $session = SessionWrapper::getInstance();
     $id = decode($formvalues['id']);
     $formvalues['id'] = $id;
     // debugMessage($formvalues);
     $formvalues['status'] = 1;
     $formvalues['password'] = $formvalues['password'];
     $formvalues['agreedtoterms'] = 1;
     $formvalues['activationdate'] = DEFAULT_DATETIME;
     $formvalues['hasacceptedinvite'] = 1;
     $user = new UserAccount();
     $user->populate($id);
     $user->processPost($formvalues);
     // debugMessage($user->toArray()); debugMessage("Error > ".$user->getErrorStackAsString()); exit();
     $user->save();
     // save notification to user's inbox
     $user->sendActivationConfirmationNotification();
     $url = $this->view->serverUrl($this->view->baseUrl('profile/view/id/' . encode($user->getID())));
     $usecase = '1.16';
     $module = '1';
     $type = USER_ACTIVATE;
     $details = "User Profile <a href='" . $url . "' class='blockanchor'>" . $user->getName() . "</a> activated";
     $browser = new Browser();
     $audit_values = $session->getVar('browseraudit');
     $audit_values['module'] = $module;
     $audit_values['usecase'] = $usecase;
     $audit_values['transactiontype'] = $type;
     $audit_values['userid'] = $session->getVar('userid');
     $audit_values['url'] = $url;
     $audit_values['transactiondetails'] = $details;
     $audit_values['status'] = "Y";
     // debugMessage($audit_values);
     $this->notify(new sfEvent($this, $type, $audit_values));
     $this->clearSession();
     $session->setVar(SUCCESS_MESSAGE, "You can now login using your Username or Email and Password");
     // $loginurl = $this->view->baseUrl("user/checklogin/email/".$user->getEmail().'/password/'.$formvalues['password']);
     $loginurl = $this->view->baseUrl("user/login");
     $this->_helper->redirector->gotoUrl($loginurl);
     return false;
 }
 function processnotificationAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $config = Zend_Registry::get("config");
     $message_collection = new Doctrine_Collection(Doctrine_Core::getTable("Message"));
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); exit;
     $recipients_array = array();
     $messagedata = array();
     $users = array();
     $execresult = array('result' => '', 'msg' => '');
     $type = $formvalues['type'];
     if ($type == 1) {
         $ismail = true;
         $issms = false;
         $msgtype = "mail";
     }
     if ($type == 2) {
         $issms = true;
         $ismail = false;
         $msgtype = "sms";
     }
     $custom_query = "";
     if ($formvalues['selecttype'] == 2) {
         if (!isArrayKeyAnEmptyString('userids', $formvalues)) {
             $users = $formvalues['userids'];
         }
     }
     if ($formvalues['selecttype'] == 4) {
         if ($ismail) {
             $users = getUsersWithEmail();
         }
         if ($issms) {
             $users = getUsersWithPhone();
         }
     }
     //debugMessage($users); exit;
     # if no receipients specified
     if (count($users) == 0) {
         $session->setVar(ERROR_MESSAGE, "Error: No Receipients specified!");
         $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS]));
         $execresult = array('result' => 'fail', 'msg' => "Error: No Receipients specified!");
         exit;
     }
     $messages = array();
     $sent = array();
     $phones = array();
     $messages['contents'] = $formvalues['contents'];
     $messages['type'] = $formvalues['type'];
     if (!isArrayKeyAnEmptyString('subject', $formvalues)) {
         $messages['subject'] = $formvalues['subject'];
     } else {
         $messages['subject'] = '';
     }
     $messages['senderid'] = 0;
     if (!isArrayKeyAnEmptyString('senderid', $formvalues)) {
         $messages['senderid'] = $formvalues['senderid'];
     }
     if (!isArrayKeyAnEmptyString('senderemail', $formvalues) && isEmptyString($session->getVar('userid'))) {
         $messages['senderemail'] = $formvalues['senderemail'];
     }
     if (!isArrayKeyAnEmptyString('sendername', $formvalues) && isEmptyString($session->getVar('userid'))) {
         $messages['sendername'] = $formvalues['sendername'];
     }
     # process receipients depending on select type
     foreach ($users as $key => $userid) {
         $user = new UserAccount();
         $id = '';
         if ($formvalues['selecttype'] == 2) {
             $id = $userid;
         }
         if ($formvalues['selecttype'] == 4) {
             $id = $key;
         }
         $user->populate($id);
         // debugMessage($memb->toArray());
         $recipients_array[$id]['recipientid'] = $user->getID();
         $messagedata[$id]['id'] = $user->getID();
         $messagedata[$id]['name'] = $user->getName();
         $messagedata[$id]['email'] = $user->getEmail();
         $messagedata[$id]['phone'] = $user->getPhone();
         $messagedata[$id]['sendemail'] = $user->allowEmailForPrivateMessage() ? 1 : 0;
         if ($ismail) {
             $sent[] = $user->getName() . ' (' . $user->getEmail() . ')';
         }
         if ($issms) {
             $sent[] = $user->getName() . ' (' . $user->getPhone() . ')';
             $phones[] = $user->getPhone();
         }
     }
     $messages['recipients'] = $recipients_array;
     $messages['membertotal'] = count($messagedata);
     $messages['usertotal'] = count($recipients_array);
     $messages['type'] = "notification";
     $messages['subtype'] = "new_" . $msgtype;
     /* debugMessage($sent); 
     		debugMessage($messagedata);  */
     $msg = new Message();
     $msg->processPost($messages);
     /* debugMessage($msg->toArray());
     		debugMessage('error is '.$msg->getErrorStackAsString()); exit(); */
     // save the messages to system inbox
     if ($msg->hasError()) {
         $session->setVar(ERROR_MESSAGE, "Error: " . $msg->getErrorStackAsString());
         $session->setVar(FORM_VALUES, $this->_getAllParams());
         $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS]));
         $execresult = array('result' => 'fail', 'msg' => "Error: " . $msg->getErrorStackAsString());
         // debugMessage($execresult);
         exit;
     } else {
         try {
             $msg->save();
             // send message to emails
             if (count($messagedata) > 0) {
                 foreach ($messagedata as $key => $receipient) {
                     $msgdetail = new MessageRecipient();
                     if (!isArrayKeyAnEmptyString('email', $receipient) && $receipient['sendemail'] == 1) {
                         $msgdetail->sendInboxEmailNotification($formvalues['senderemail'], $formvalues['sendername'], $messages['subject'], $receipient['email'], $receipient['name'], $messages['contents']);
                     }
                 }
             }
             // send message to phones
             if (count($phones) > 0) {
                 $messagechuncks = array_chunk($messagedata, 100, true);
                 if (count($messagedata) <= 100) {
                     $phonelist = implode(',', $phones);
                     //$result = sendSMSMessage($phonelist, $messages['contents'], '', $msg->getID());
                     // debugMessage($result); exit;
                 } else {
                     foreach ($messagechuncks as $key => $messagegrp) {
                         $phones_temp_array = array();
                         foreach ($messagegrp as $keynest => $messageline) {
                             $phones_temp_array[] = $messageline['phone'];
                         }
                         $phonelist = implode(',', $phones_temp_array);
                         // $result = sendSMSMessage($phonelist, $messages['contents'], '', $msg->getID());
                         // debugMessage($result);
                     }
                 }
             }
             if (count($messagedata) == 1) {
                 $key = current(array_keys($messagedata));
                 if ($ismail) {
                     $rcpt = $messagedata[$key]['name'] . ' (' . $messagedata[$key]['email'] . ')';
                     $sentmessage = "Message sent to " . $rcpt;
                     $session->setVar(SUCCESS_MESSAGE, $sentmessage);
                 }
                 if ($issms) {
                     $rcpt = $messagedata[$key]['name'] . ' (' . $messagedata[$key]['phone'] . ')';
                     $sentmessage = "Message sent to " . $rcpt;
                     $session->setVar(SUCCESS_MESSAGE, $sentmessage);
                 }
             } else {
                 $sentmessage = "Message successfully sent to <b>" . count($messagedata) . "</b> member(s). <br />See full list of recipient(s) at the bottom of this page.";
                 $sentresult = createHTMLListFromArray($sent, 'successmsg alert alert-success');
                 $session->setVar('sentlist', $sentresult);
                 $session->setVar(SUCCESS_MESSAGE, "Message sent to " . count($messagedata) . " members. <br />See full list of recipients at the bottom of this page.");
             }
             $execresult = array('result' => 'success', 'msg' => $sentmessage);
         } catch (Exception $e) {
             $session->setVar(ERROR_MESSAGE, "An error occured in sending the message. " . $e->getMessage());
             $session->setVar(FORM_VALUES, $this->_getAllParams());
             $execresult = array('result' => 'success', 'msg' => "An error occured in sending the message. " . $e->getMessage());
         }
     }
     // exit;
     $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS]));
     echo json_encode($execresult);
 }
Exemplo n.º 3
0
 public function processresetpasswordAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues);
     $user = new UserAccount();
     $user->populate(decode($this->_getParam('id')));
     // debugMessage($user->toArray());
     $user->setUsername($formvalues['username']);
     $user->setStatus(1);
     $user->setAgreedToTerms(1);
     if (isEmptyString($user->getActivationDate())) {
         $startdate = date("Y-m-d H:i:s", time());
         $user->setActivationDate($startdate);
     }
     // exit();
     if ($user->resetPassword($this->_getParam('password'))) {
         // save to audit
         $url = $this->view->serverUrl($this->view->baseUrl('profile/view/id/' . encode($user->getID())));
         $usecase = '1.10';
         $module = '1';
         $type = USER_RESET_PASSWORD_CONFIRM;
         $details = "Reset password confirmed for <a href='" . $url . "' class='blockanchor'>" . $user->getName() . "</a>";
         $browser = new Browser();
         $audit_values = $session->getVar('browseraudit');
         $audit_values['module'] = $module;
         $audit_values['usecase'] = $usecase;
         $audit_values['transactiontype'] = $type;
         $audit_values['userid'] = $session->getVar('userid');
         $audit_values['url'] = $url;
         $audit_values['transactiondetails'] = $details;
         $audit_values['status'] = "Y";
         // debugMessage($audit_values);
         $this->notify(new sfEvent($this, $type, $audit_values));
         // send a link to enable the user to recover their password
         $session->setVar(SUCCESS_MESSAGE, "Sucessfully saved. You can now log in using your new Password");
         $this->_helper->redirector->gotoUrl($this->view->baseUrl("user/login"));
     } else {
         // echo "cannot reset password";
         // send an error message that no user with that email was found
         $session = SessionWrapper::getInstance();
         $session->setVar(ERROR_MESSAGE, $user->getErrorStackAsString());
         $session->setVar(FORM_VALUES, $this->_getAllParams());
         $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE)));
     }
 }
 function resetpasswordAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $session = SessionWrapper::getInstance();
     $this->_translate = Zend_Registry::get("translate");
     $id = decode($this->_getParam('id'));
     // debugMessage($id);
     $user = new UserAccount();
     $user->populate($id);
     debugMessage($user->toArray());
     // $formvalues = array('email'=>$user->getEmail());
     $user->setEmail($user->getEmail());
     // debugMessage('error '.$user->getErrorStackAsString()); exit();
     if ($user->recoverPassword()) {
         $session->setVar(SUCCESS_MESSAGE, sprintf($this->_translate->translate('profile_change_password_admin_confirmation'), $user->getName()));
         // send a link to enable the user to recover their password
         // debugMessage('no error found ');
         $view = new Zend_View();
         $url = $this->view->serverUrl($this->view->baseUrl('profile/view/id/' . encode($user->getID())));
         $usecase = '1.9';
         $module = '1';
         $type = USER_RESET_PASSWORD;
         $details = "Reset password request. Reset link sent to <a href='" . $url . "' class='blockanchor'>" . $user->getName() . "</a>";
         $browser = new Browser();
         $audit_values = $session->getVar('browseraudit');
         $audit_values['module'] = $module;
         $audit_values['usecase'] = $usecase;
         $audit_values['transactiontype'] = $type;
         $audit_values['userid'] = $session->getVar('userid');
         $audit_values['url'] = $url;
         $audit_values['transactiondetails'] = $details;
         $audit_values['status'] = "Y";
         // debugMessage($audit_values);
         $this->notify(new sfEvent($this, $type, $audit_values));
     } else {
         $session->setVar(ERROR_MESSAGE, $user->getErrorStackAsString());
         $session->setVar(FORM_VALUES, $this->_getAllParams());
         // debugMessage('no error found ');
     }
     // exit();
     $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS)));
 }
 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);
     }
 }