function updatestatusAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $formvalues = $this->_getAllParams(); debugMessage($formvalues); $session = SessionWrapper::getInstance(); $this->_translate = Zend_Registry::get("translate"); $formvalues['id'] = $id = $formvalues['id']; $formvalues['dateapproved'] = date("Y-m-d H:i:s", strtotime('now')); $formvalues['approvedbyid'] = $session->getVar('userid'); // debugMessage($formvalues); $leave = new Leave(); $leave->populate($id); $leave->setStatus($formvalues['status']); $leave->setDateApproved(DEFAULT_DATETIME); $leave->setApprovedByID($session->getVar('userid')); if (!isArrayKeyAnEmptyString('reason', $formvalues)) { $leave->setReason("<br/>Rejected with remarks: " . $formvalues['reason']); } try { $leave->save(); $leave->afterApprove($formvalues['status']); $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate($formvalues[SUCCESS_MESSAGE])); } catch (Exception $e) { // debugMessage('error '.$e->getMessage()); $session->setVar(ERROR_MESSAGE, $e->getMessage()); } // exit(); $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS])); }
public function errorAction() { // $this->_helper->layout->disableLayout(); // debugMessage($this->toArray()); $errors = $this->_getParam('error_handler'); if (!$errors) { $this->view->message = 'You have reached the error page'; debugMessage('$this->view->message. No Error detected'); return; } $exception = $errors->exception; // debugMessage($exception); $vars = get_object_vars($exception); $error_list = createHTMLCommaListFromArray($vars); // debugMessage('errors are '.$error_list); // debugMessage(get_class($errors->exception)); debugMessage($errors->type); // exit(); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found $this->getResponse()->setHttpResponseCode(404); $this->view->message = 'Page not found ' . $errors->exception; break; default: // application error $this->getResponse()->setHttpResponseCode(500); // $this->view->message = 'Application error'.$errors->exception; $this->view->message = $error_list; $string = '<div class="divider30"></div> <div class="row-fluid"> <div class="col-sm-12"> <div class="alert alert-danger">Application Runtime Error</div> <p class="bg-warning padding10">' . $error_list . '></p> </div> </div> '; // debugMessage($string); /* */ break; } // Log exception, if logger available $log = $this->getLog(); if ($log) { $log->crit($this->view->message, $error_list); } // conditionally display exceptions if ($this->getInvokeArg('displayExceptions') == true) { // $this->view->exception = $errors->exception; $this->view->exception = $error_list; } $this->view->request = $errors->request; /**/ }
function checkinAction() { $session = SessionWrapper::getInstance(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $formvalues = $this->_getAllParams(); debugMessage('test'); $testarray = array("userid" => 15, 'datein' => 'Jan 27, 2015', 'timein' => '08:00 AM', 'dateout' => '', 'timeout' => '', 'reason' => '', 'createdby' => 15); $attendance = new Attendance(); debugMessage($attendance->toArray()); $attendance->processPost($testarray); debugMessage($attendance->toArray()); debugMessage('errors are ' . $attendance->getErrorStackAsString()); try { $attendance->save(); debugMessage('saved successfully'); debugMessage($attendance->toArray()); } catch (Exception $e) { debugMessage('error: ' . $e->getMessage()); } }
function processreplyAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $formvalues = $this->_getAllParams(); debugMessage($formvalues); $messages = array(); $messages['senderid'] = $formvalues['senderid']; $messages['parentid'] = $formvalues['parentid']; $messages['subject'] = $formvalues['subject']; $messages['contents'] = $formvalues['contents']; $recipients_array = array(); $users = array(); $users = $formvalues['recipientids']; foreach ($users as $userid) { $recipients_array[$userid]['recipientid'] = $userid; } $messages['recipients'] = $recipients_array; // debugMessage($messages); $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, "An error occured in sending the message. " . $msg->getErrorStackAsString()); } else { try { $msg->save(); // copy message to recepient's email of specified / required for admin contact $messagereceipients = $msg->getRecipients(); if ($this->_getParam('copytoemail') == 1) { foreach ($messagereceipients as $messageuser) { if (!isEmptyString($messageuser->getRecipient()->getEmail())) { $messageuser->sendInboxEmailNotification(); } } } if ($this->_getParam('copytophone') == 1) { foreach ($messagereceipients as $messageuser) { if (!isEmptyString($messageuser->getRecipient()->getPhone())) { # check if user has phone number on profile $messageuser->sendSmsNotification(); } } } // copy message to user's phone if specified $session->setVar(SUCCESS_MESSAGE, "Message successfully replied. "); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, "An error occured in sending the message. " . $e->getMessage()); } } $this->_helper->redirector->gotoUrl(decode($formvalues[URL_SUCCESS])); // exit(); }
function sendPayslipNotification() { $template = new EmailTemplate(); # create mail object $mail = getMailInstance(); $view = new Zend_View(); $session = SessionWrapper::getInstance(); // assign values $template->assign('firstname', $this->getUser()->getFirstName()); $subject = "Payslip " . date('F Y', strtotime($this->getPayroll()->getStartDate())); $save_toinbox = true; $type = "payroll"; $subtype = "payslip_generated"; $viewurl = $template->serverUrl($template->baseUrl('temp/' . $this->getPDFName() . '.pdf')); $message_contents = "<p>This is to confirm that your Payslip for <b>" . date('F Y', strtotime($this->getPayroll()->getStartDate())) . "</b> has been completed and attached.</p>\n\t\t<p>You can also view it online <a href='" . $viewurl . "'>click here<a></p>\n\t\t<br />\n\t\t<p>" . $this->getPayroll()->getCreator()->getName() . "<br />\n\t\t" . getAppName() . "</p>\n\t\t"; $template->assign('contents', $message_contents); $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); // configure base stuff $mail->addTo($this->getUser()->getEmail(), $this->getUser()->getName()); // set the send of the email address $mail->setFrom(getDefaultAdminEmail(), getDefaultAdminName()); $mail->setSubject($subject); // add attachment $content = file_get_contents($this->getPDFPath()); // e.g. ("attachment/abc.pdf") $attachment = new Zend_Mime_Part($content); $attachment->type = 'application/pdf'; $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $attachment->encoding = Zend_Mime::ENCODING_BASE64; $attachment->filename = $this->getPDFName(); // name of file $mail->addAttachment($attachment); // render the view as the body of the email $html = $template->render('default.phtml'); $mail->setBodyHtml($html); // debugMessage($html); // exit(); if ($this->getUser()->allowEmailForPayslip() && !isEmptyString($this->getUser()->getEmail())) { try { $mail->send(); // $session->setVar("custommessage1", "Email sent to ".$this->getUser()->getEmail()); } catch (Exception $e) { debugMessage('Email notification not sent! ' . $e->getMessage()); $session->setVar(ERROR_MESSAGE, 'Email notification not sent! ' . $e->getMessage()); } } $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); $mail->clearFrom(); if ($save_toinbox) { # save copy of message to user's application inbox $message_dataarray = array("senderid" => DEFAULT_ID, "subject" => $subject, "contents" => $message_contents, "html" => $html, "type" => $type, "subtype" => $subtype, "refid" => $this->getID(), "recipients" => array(md5(1) => array("recipientid" => $this->getUserID()))); // debugMessage($message_dataarray); // process message data $message = new Message(); $message->processPost($message_dataarray); $message->save(); } return true; }
function reactivateAllAccounts() { $user_collection = new Doctrine_Collection(Doctrine_Core::getTable("UserAccount")); $users = $this->getUsers(); //debugMessage($users->toArray()); if ($users->count() > 0) { foreach ($users as $user) { if ($user->isUserInActive() && $user->getActivationKey() == md5($this->getCompanyID())) { $user->setStatus(1); $user->setActivationKey(''); $user_collection->add($user); } } // debugMessage($user_collection->toArray()); } if ($user_collection->count() > 0) { try { $user_collection->save(); } catch (Exception $e) { debugMessage("An error occured in updating status. " . $e->getMessage()); } } return true; }
function approveAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $formvalues = $this->_getAllParams(); debugMessage($formvalues); $id = decode($formvalues['id']); $formvalues['id'] = $id; $successmessage = ""; if (!isArrayKeyAnEmptyString('id', $formvalues)) { if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 1; } $ledger = new Ledger(); $ledger->populate($id); if (!isArrayKeyAnEmptyString('reason', $formvalues)) { $ledger->setRemarks($ledger->getRemarks() . "<br/> Rejected with remarks: " . $formvalues['reason']); } $ledger->setDateApproved(DEFAULT_DATETIME); $ledger->setApprovedByID($session->getVar('userid')); $ledger->setStatus($formvalues['status']); // debugMessage($ledger->toArray()); exit(); try { $ledger->save(); $msg = "Successfully Approved"; if ($formvalues['status'] == 4) { $msg = "Successfully Rejected"; } $session->setVar(SUCCESS_MESSAGE, $msg); $ledger->afterApprove(); } catch (Exception $e) { // debugMessage($e->getMessage()); $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); }
/** * Map firephp trace function for easy disabling */ function trace($message, $options = '') { if (confGet('USE_FIREPHP')) { global $g_firephp; if (!isset($g_firephp)) { require_once 'lib/firephp/FirePHP.class.php'; #require_once('lib/firephp/fb.php'); $g_firephp = FirePHP::getInstance(true); $options = array('maxObjectDepth' => 1, 'maxArrayDepth' => 1, 'useNativeJsonEncode' => true, 'includeLineNumbers' => true); $g_firephp->setOptions($options); } $g_firephp->trace($message, $options); } else { debugMessage($message); } }
/** * Backs up the database with an option of sending the backup via email * */ function backupAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get('config'); $formvalues = $this->_getAllParams(); $result = array(); $showverbose = true; $detect = ''; if (!isEmptyString($this->_getParam('triggered'))) { $showverbose = false; } if ($this->_getParam('autocron') == 'yes') { $detect = '_cron'; } # get the database connection parameters $db_params = Zend_Controller_Front::getInstance()->getParam("bootstrap")->getPluginResource('db')->getParams(); // debugMessage($db_params); # configure your database variables below: $host_array = explode(":", $db_params['host']); $dbhost = $host_array[0]; # Server address of your MySQL Server $dbuser = $db_params['username']; # Username to access MySQL database $dbpass = $db_params['password']; # Password to access MySQL database $dbname = $db_params['dbname']; # Database Name $dbport = isArrayKeyAnEmptyString(1, $host_array) ? "3306" : "3356"; // exit(); # Optional Options You May Optionally Configure $use_gzip = $config->backup->usegzip; # Set to No if you don't want the files sent in .gz format $remove_sql_file = $config->backup->removesqlfile; # Set this to yes if you want to remove the .sql file after gzipping. Yes is recommended. $remove_gzip_file = $config->backup->removegzipfile; # Set this to yes if you want to delete the gzip file also. I recommend leaving it to "no" # Configure the path that this script resides on your server. // $savepath = APPLICATION_PATH.$config->backup->scriptfolder; # Full path to this directory. Do not use trailing slash! $savepath = BASE_PATH . DIRECTORY_SEPARATOR . 'backup'; // debugMessage($savepath); $send_email = $config->backup->sendemail; # Do you want this database backup sent to your email? Fill out the next 2 lines # email address $backupemail = $config->backup->backupemail; if (!isEmptyString($this->_getParam('email'))) { $backupemail = $this->_getParam('email'); } # attachment mime type - default for a text attachment $attachment_mime_type = "text/plain"; # set the maximum execution time to ensure that the backup is completed ini_set("max_execution_time", 600); $date = date("dMy_Hi"); # sql backup filename $sqlattachmentname = $dbname . $detect . "_" . $date . ".sql"; # zipped backup filename $gzipattachmentname = $dbname . "_" . $date . ".tar.gz"; # sql backup path $sqlscriptpath = $savepath . DIRECTORY_SEPARATOR . $sqlattachmentname; # zipped backup path $zipfilepath = $savepath . DIRECTORY_SEPARATOR . $gzipattachmentname; # before backingup, move all current files at root to the archive folder $sqlfiles = glob($savepath . DIRECTORY_SEPARATOR . '*.sql'); $tarfiles = glob($savepath . DIRECTORY_SEPARATOR . '*.tar.gz'); $archivefiles = glob($savepath . DIRECTORY_SEPARATOR . 'archive' . DIRECTORY_SEPARATOR . '*'); // debugMessage($sqlfiles); foreach ($sqlfiles as $afile) { $afile_filename = basename($afile); rename($afile, $savepath . DIRECTORY_SEPARATOR . 'archive' . DIRECTORY_SEPARATOR . $afile_filename); } foreach ($tarfiles as $afile) { $afile_filename = basename($afile); rename($afile, $savepath . DIRECTORY_SEPARATOR . 'archive' . DIRECTORY_SEPARATOR . $afile_filename); } $time = time(); foreach ($archivefiles as $file) { if (is_file($file)) { $retentiondays = $config->backup->retentionperiod; $seconds = 60 * 60 * 24 * $retentiondays; // number of retention days for backup files. defaults to 7 days. // $seconds = 60; // debugMessage($time - filemtime($file)); if ($time - filemtime($file) >= $seconds) { // 2 days // debugMessage($file); unlink($file); } } } if ($this->_getParam('sql') == '1') { $use_gzip = "no"; $remove_sql_file = "no"; $remove_gzip_file = "no"; } $tablesonly_sql = ""; $ignore_sql = " "; if (!isEmptyString($this->_getParam('ignorelist'))) { $tables = str_replace(' ', '', $this->_getParam('ignorelist')); $tablearray = explode(',', $tables); if (count($tablearray) > 0) { foreach ($tablearray as $value) { $ignore_sql .= " --ignore-table=" . $dbname . "." . $value . " "; } } //debugMessage($ignore_sql); } if (!isEmptyString($this->_getParam('tablelist'))) { $tables = str_replace(' ', '', $this->_getParam('tablelist')); $tablearray = explode(',', $tables); if (count($tablearray) > 0) { foreach ($tablearray as $value) { $tablesonly_sql .= " " . $value . " "; } } // debugMessage($tablesonly_sql); } $backupcommand = "mysqldump -R --add-drop-table --complete-insert --add-locks --quote-names --lock-tables --skip-routines -h " . $ignore_sql . " " . $dbhost . " -P " . $dbport . " -u " . $dbuser . " -p" . $dbpass . " " . $dbname . $tablesonly_sql . ' > "' . $sqlscriptpath . '"'; debugMessage($backupcommand); // exit(); try { if (passthru($backupcommand)) { // exit(); if ($showverbose) { debugMessage(getAppName() . " Database backup completed to " . $sqlscriptpath); } # create tar archive if ($use_gzip == "yes") { $zipline = "tar -czf " . $zipfilepath . " " . $sqlscriptpath; passthru($zipline); debugMessage($zipline); debugMessage("Gzip of backup completed"); } // exit(); # set email attachment name and path depending on weather to form zip or not if ($use_gzip == "yes") { $attachmentpath = $zipfilepath; $attachmentname = $gzipattachmentname; $attachment_mime_type = "application/gzip"; } else { $attachmentpath = $sqlscriptpath; $attachmentname = $sqlattachmentname; } # send an email with a copy of the backup if ($send_email == "yes") { $mail = Zend_Registry::get('mail'); # build the mailer class // $mail->addTo($config->get(APPLICATION_ENV)->get("databasebackupemail")); $mail->addTo($backupemail); $mail->setFrom($config->notification->defaultadminemail, $config->notification->defaultadminname); $mail->setSubject(sprintf($this->_translate->_("database_backup_subject"), getAppName(), date("j F Y h:iA"))); # Subject in the email to be sent. $mail->setBodyHtml(sprintf($this->_translate->_("database_backup_body"), getAppName())); # Brief Message. # attachmentpath is the full path to the file and attachmentname is the name of the file $at = new Zend_Mime_Part(file_get_contents($attachmentpath)); $at->filename = $attachmentname; $at->disposition = Zend_Mime::DISPOSITION_INLINE; $at->encoding = Zend_Mime::ENCODING_BASE64; $at->type = $attachment_mime_type; $mail->addAttachment($at); // $mail->send(); try { $mail->send(); $message = getAppName() . " Database backup sent to " . $backupemail; if ($showverbose) { debugMessage($message); } else { $result['message'] = $message; $result['result'] = 1; } } catch (Exception $e) { $message = 'Email notification not sent! ' . $e->getMessage(); if ($showverbose) { debugMessage($message); } else { debugMessage($message); $result['message'] = $message; $result['result'] = 0; } } $mail->clearRecipients(); $mail->clearSubject(); $mail->setBodyHtml(''); $mail->clearFrom(); } # remove sql file if condition is set if ($remove_sql_file == "yes") { passthru("rm -rf " . $sqlscriptpath); } # remove tar file if condition is set if ($remove_gzip_file == "yes") { passthru("rm -rf " . $attachmentpath); } if ($this->_getParam('download') == '1') { header('Location: ' . $this->view->serverUrl($this->view->baseUrl('backup/' . $sqlattachmentname))); exit; // file headers to force a download /*header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); // to handle spaces in the file names header("Content-Disposition: inline; filename=\"$sqlscriptpath\""); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); readfile($savepath);*/ } if (!$showverbose) { echo json_encode($result); } } } catch (Exception $e) { debugMessage($e->getMessage()); } }
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 inviteuserAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $formvalues = $this->_getAllParams(); debugMessage($this->_getAllParams()); $user = new UserAccount(); $user->populate($formvalues['id']); // debugMessage($user->toArray()); exit(); try { $user->inviteOne(); $session->setVar('invitesuccess', "Email Invitation sent to " . $user->getEmail()); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); // exit(); }
public function issuepayslipsAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $formvalues = $this->_getAllParams(); // debugMessage($formvalues); exit; $config = Zend_Registry::get("config"); // generate the payslips silently via ajax $payroll = new Payroll(); $payroll->populate($this->_getParam('id')); $employees = $payroll->getdetails(); // debugMessage($employees->toArray()); foreach ($employees as $employee) { if ($employee->getIsIgnored() != 1 && $employee->getNetPay() > 0) { // ignore users who are skipped on payroll or have 0 netpay $payrolldetailid = $employee->getID(); $path = $employee->getPDFPath(); $pdfurl = $this->view->serverUrl($this->view->baseUrl('user/view/id/' . encode($employee->getUserID()) . '/tab/payment/payrollid/' . $payrolldetailid . '/ref/view/print/1/pgc/1/payslipview/1/pdf/1/source/payroll')); // debugMessage($pdfurl); $pdfresult = trim(file_get_contents($pdfurl)); $html = decode($pdfresult); // debugMessage($html); // exit; if (!isEmptyString($html)) { try { $mpdfpath = BASE_PATH . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'mpdf' . DIRECTORY_SEPARATOR . 'mpdf.php'; // debugMessage('pdf '.$mpdfpath); ini_set('memory_limit', '128M'); require_once $mpdfpath; // ob_get_clean(); $mpdf = new mPDF('win-1252', 'A4', '', '', 20, 15, 40, 20, 10, 10); $mpdf->useOnlyCoreFonts = true; // false is default $mpdf->SetProtection(array('print')); $mpdf->SetTitle("Payslip - " . $employee->getUser()->Name()); $mpdf->SetAuthor(getAppName()); $mpdf->SetWatermarkText(getCompanyName()); $mpdf->showWatermarkText = true; $mpdf->watermark_font = 'DejaVuSansCondensed'; $mpdf->watermarkTextAlpha = 0.1; $mpdf->SetDisplayMode('fullpage'); $mpdf->WriteHTML($html); $mpdf->Output($path); // $mpdf->Output($employee->getPDFName().'.pdf', 'I'); } catch (Exception $e) { debugMessage('error ' . $e->getMessage()); } if (file_exists($path)) { debugMessage('pdf ' . $employee->getPDFName() . ' created '); // $employee->afterPayslipGeneration(); } else { debugMessage('pdf missing'); } } } } $session->setVar("issuepayslips", '0'); // reset flag for determining if payslips are sent }
public function deleteAction() { $this->_setParam("action", ACTION_DELETE); $session = SessionWrapper::getInstance(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $formvalues = $this->_getAllParams(); // debugMessage($formvalues); // exit; $successurl = decode($formvalues[URL_SUCCESS]); if (!isArrayKeyAnEmptyString(SUCCESS_MESSAGE, $formvalues)) { $successmessage = decode($formvalues[SUCCESS_MESSAGE]); } // debugMessage($successurl); $payroll = new Payroll(); $id = is_numeric($formvalues['id']) ? $formvalues['id'] : decode($formvalues['id']); // debugMessage($id); $payroll->populate($id); debugMessage($payroll->toArray()); $deletetrxns = $payroll->getLedgerDeleteTrxns(); if ($deletetrxns->count() > 0) { $deletetrxns->delete(); } /* debugMessage($payroll->getLedgerDeleteTrxns()->toArray()); exit(); */ if ($payroll->delete()) { $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate("global_delete_success")); $successmessage = $this->_getParam(SUCCESS_MESSAGE); if (!isEmptyString($successmessage)) { $session->setVar(SUCCESS_MESSAGE, $successmessage); } } $this->_helper->redirector->gotoUrl($successurl); }
public function processlogoAction() { // disable rendering of the view and layout so that we can just echo the AJAX output $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $formvalues = $this->_getAllParams(); debugMessage($this->_getAllParams()); // exit(); $company = new Company(); $company->populate(decode($this->_getParam('id'))); // only upload a file if the attachment field is specified $upload = new Zend_File_Transfer(); // set the file size in bytes $upload->setOptions(array('useByteString' => false)); // Limit the extensions to the specified file extensions $upload->addValidator('Extension', false, $config->uploads->photoallowedformats); $upload->addValidator('Size', false, $config->uploads->photomaximumfilesize); // base path for profile pictures $destination_path = BASE_PATH . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . "company" . DIRECTORY_SEPARATOR . "comp_"; // determine if user has destination avatar folder. Else user is editing there picture if (!is_dir($destination_path . $company->getID())) { // no folder exits. Create the folder mkdir($destination_path . $company->getID(), 0777); } // set the destination path for the image $profilefolder = $company->getID(); $destination_path = $destination_path . $profilefolder . DIRECTORY_SEPARATOR . "logo"; if (!is_dir($destination_path)) { mkdir($destination_path, 0777); } // create archive folder for each user $archivefolder = $destination_path . DIRECTORY_SEPARATOR . "archive"; if (!is_dir($archivefolder)) { mkdir($archivefolder, 0777); } $oldfilename = $company->getLogo(); // debugMessage($destination_path); exit; $upload->setDestination($destination_path); // the profile image info before upload $file = $upload->getFileInfo('logoimage'); $uploadedext = findExtension($file['logoimage']['name']); $currenttime = mktime(); $currenttime_file = $currenttime . '.' . $uploadedext; $thefilename = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime_file; $thelargefilename = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime_file; $updateablefile = $destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime; $updateablelarge = $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime; // rename the base image file $upload->addFilter('Rename', array('target' => $thefilename, 'overwrite' => true)); // exit(); // process the file upload if ($upload->receive()) { // debugMessage('Completed'); $file = $upload->getFileInfo('logoimage'); // debugMessage($file); $basefile = $thefilename; // convert png to jpg if (in_array(strtolower($uploadedext), array('png', 'PNG', 'gif', 'GIF'))) { ak_img_convert_to_jpg($thefilename, $updateablefile . '.jpg', $uploadedext); unlink($thefilename); } $basefile = $updateablefile . '.jpg'; // new profilenames $newlargefilename = "large_" . $currenttime_file; // generate and save thumbnails for sizes 250, 125 and 50 pixels resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . 'large_' . $currenttime . '.jpg', 400); resizeImage($basefile, $destination_path . DIRECTORY_SEPARATOR . $currenttime . '.jpg', 165); // unlink($thefilename); unlink($destination_path . DIRECTORY_SEPARATOR . 'base_' . $currenttime . '.jpg'); // exit(); // update the useraccount with the new profile images try { $company->setLogo($currenttime . '.jpg'); $company->save(); // check if user already has profile picture and archive it $ftimestamp = current(explode('.', $company->getLogo())); $allfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*.*'); $currentfiles = glob($destination_path . DIRECTORY_SEPARATOR . '*' . $ftimestamp . '*.*'); // debugMessage($currentfiles); $deletearray = array(); foreach ($allfiles as $value) { if (!in_array($value, $currentfiles)) { $deletearray[] = $value; } } // debugMessage($deletearray); if (count($deletearray) > 0) { foreach ($deletearray as $afile) { $afile_filename = basename($afile); rename($afile, $archivefolder . DIRECTORY_SEPARATOR . $afile_filename); } } $session->setVar(SUCCESS_MESSAGE, "Successfully uploaded. Crop to resize the image and click 'Crop' to save changes."); $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); $session->setVar(FORM_VALUES, $this->_getAllParams()); $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE))); } } else { // debugMessage($upload->getMessages()); $uploaderrors = $upload->getMessages(); $customerrors = array(); if (!isArrayKeyAnEmptyString('fileUploadErrorNoFile', $uploaderrors)) { $customerrors['fileUploadErrorNoFile'] = "Please browse for image on computer"; } if (!isArrayKeyAnEmptyString('fileExtensionFalse', $uploaderrors)) { $custom_exterr = sprintf($this->_translate->translate('upload_invalid_ext_error'), $config->uploads->photoallowedformats); $customerrors['fileExtensionFalse'] = $custom_exterr; } if (!isArrayKeyAnEmptyString('fileUploadErrorIniSize', $uploaderrors)) { $custom_exterr = sprintf($this->_translate->translate('upload_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0)); $customerrors['fileUploadErrorIniSize'] = $custom_exterr; } if (!isArrayKeyAnEmptyString('fileSizeTooBig', $uploaderrors)) { $custom_exterr = sprintf($this->_translate->translate('upload_invalid_size_error'), formatBytes($config->uploads->photomaximumfilesize, 0)); $customerrors['fileSizeTooBig'] = $custom_exterr; } $session->setVar(ERROR_MESSAGE, 'The following errors occured <ul><li>' . implode('</li><li>', $customerrors) . '</li></ul>'); $session->setVar(FORM_VALUES, $this->_getAllParams()); $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE))); } }
function debug_instance_shutdown() { debug_onShutdown('P28dLKkZZPjKsQzjkIELGRpC'); debugMessage("instance shutdown"); debugMessage("peak memory usage: " . memory_get_peak_usage() . ' bytes'); }
public function processrolesAction() { $session = SessionWrapper::getInstance(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $this->_translate = Zend_Registry::get("translate"); $post_array = $this->_getAllParams(); // debugMessage($this->_getAllParams()); exit; $id = $post_array['id']; $post_array['id'] = decode($id); $perms = $post_array['permissions']; unset($post_array['permissions']); if (isEmptyString($id)) { // add new role first $newrole = new AclGroup(); $post_array['createdby'] = $session->getVar('userid'); $newrole->processPost($post_array); // debugMessage($newrole->toArray()); debugMessage('error is '.$newrole->getErrorStackAsString()); $newrole->save(); $post_array['id'] = $newrole->getID(); } else { // update role first $newrole = new AclGroup(); $newrole->populate(decode($id)); $newrole->processPost($post_array); // debugMessage($newrole->toArray()); debugMessage('error is '.$newrole->getErrorStackAsString()); // exit(); $newrole->save(); } // exit; $role = new AclGroup(); $role->populate($post_array['id']); $permissions = $role->getPermissions(); $permissions_array = $permissions->toArray(); $post_array['permissions'] = $perms; // set audit entry before save if (!isArrayKeyAnEmptyString('permissions', $post_array)) { $data = array(); foreach ($post_array['permissions'] as $key => $value) { $data[$key] = $value; $post_array['permissions'][$key]['groupid'] = $post_array['id']; if (isArrayKeyAnEmptyString('flag', $value)) { $post_array['permissions'][$key]['flag'] = 0; } else { $post_array['permissions'][$key]['flag'] = trim(intval($value['flag'])); } if (isArrayKeyAnEmptyString('create', $value)) { $post_array['permissions'][$key]['create'] = 0; } else { $post_array['permissions'][$key]['create'] = trim(intval($value['create'])); } if (isArrayKeyAnEmptyString('edit', $value)) { $post_array['permissions'][$key]['edit'] = 0; } else { $post_array['permissions'][$key]['edit'] = trim(intval($value['edit'])); } if (isArrayKeyAnEmptyString('view', $value)) { $post_array['permissions'][$key]['view'] = 0; } else { $post_array['permissions'][$key]['view'] = trim(intval($value['view'])); } if (isArrayKeyAnEmptyString('list', $value)) { $post_array['permissions'][$key]['list'] = 0; } else { $post_array['permissions'][$key]['list'] = trim(intval($value['list'])); } if (isArrayKeyAnEmptyString('delete', $value)) { $post_array['permissions'][$key]['delete'] = 0; } else { $post_array['permissions'][$key]['delete'] = trim(intval($value['delete'])); } if (isArrayKeyAnEmptyString('approve', $value)) { $post_array['permissions'][$key]['approve'] = 0; } else { $post_array['permissions'][$key]['approve'] = trim(intval($value['approve'])); } if (isArrayKeyAnEmptyString('export', $value)) { $post_array['permissions'][$key]['export'] = 0; } else { $post_array['permissions'][$key]['export'] = trim(intval($value['export'])); } if (isArrayKeyAnEmptyString('id', $value)) { $post_array['permissions'][$key]['id'] = NULL; } $post_array['permissions'][$key]['createdby'] = $session->getVar('userid'); $post_array['permissions'][$key]['datecreated'] = getCurrentMysqlTimestamp(); if (!isArrayKeyAnEmptyString('id', $value)) { $post_array['permissions'][$key]['lastupdatedby'] = $session->getVar('userid'); $post_array['permissions'][$key]['lastupdatedate'] = getCurrentMysqlTimestamp(); } else { $post_array['createdby'] = $session->getVar('userid'); } } // end loop through permissions to unset empty groupids } // debugMessage($post_array); exit(); if (!isEmptyString($id)) { $beforesave = $post_array['permissions']; // debugMessage($beforesave); } $perm_collection = new Doctrine_Collection(Doctrine_Core::getTable("AclPermission")); foreach ($post_array['permissions'] as $key => $value) { $perm = new AclPermission(); if (!isArrayKeyAnEmptyString('id', $value)) { $perm->populate($value['id']); } $perm->processPost($value); if ($perm->isValid()) { $perm_collection->add($perm); } else { debugMessage('Error: ' . $perm->getErrorStackAsString()); exit; } } try { $perm_collection->save(); if (isEmptyString($id)) { # add log to audit trail $url = $this->view->serverUrl($this->view->baseUrl('role/view/id/' . encode($newrole->getID()))); $usecase = '0.4'; $module = '0'; $type = SYSTEM_CREATEROLE; $details = "Role <a href='" . $url . "' class='blockanchor'>" . $newrole->getName() . "</a> created"; } else { $url = $this->view->serverUrl($this->view->baseUrl('role/view/id/' . encode($newrole->getID()))); $usecase = '0.5'; $module = '0'; $type = SYSTEM_UPDATEROLE; $details = "Role <a href='" . $url . "' class='blockanchor'>" . $newrole->getName() . "</a> updated"; $prejson = json_encode($beforesave); $after = $perm_collection->toArray(); debugMessage($after); $postjson = json_encode($post_array); // debugMessage($postjson); // $diff = array_diff($beforesave, $after); // debugMessage($diff); $jsondiff = ''; // debugMessage($jsondiff); } $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'] = $details; $audit_values['url'] = $url; if (!isEmptyString($id)) { $audit_values['isupdate'] = 1; $audit_values['prejson'] = $prejson; $audit_values['postjson'] = $postjson; $audit_values['jsondiff'] = $jsondiff; } // debugMessage($audit_values); $this->notify(new sfEvent($this, $type, $audit_values)); if (!isEmptyString($this->_getParam(SUCCESS_MESSAGE))) { $session->setVar(SUCCESS_MESSAGE, $this->_translate->translate($this->_getParam(SUCCESS_MESSAGE))); } $this->_helper->redirector->gotoUrl($this->view->baseUrl("role/view/id/" . encode($role->getID()))); } catch (Exception $e) { // debugMessage($perm_collection->toArray()); // debugMessage('error in save. '.$e->getMessage()); $session->setVar(ERROR_MESSAGE, $e->getMessage()); $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_FAILURE))); } }
function sendSMSMessage($to, $txt, $source = '', $msgid = '') { $session = SessionWrapper::getInstance(); $phone = $to; $message = $txt; $sendsms = true; if (isEmptyString($source)) { $source = getSmsSenderName(); } $server = getSmsServer(); $username = getSmsUsername(); $password = getSmsPassword(); $parameters = array('username' => $username, 'password' => $password, 'type' => 'TEXT', 'sender' => $source, 'mobile' => $phone, 'message' => $message); // debugMessage($parameters); $client = new Zend_Http_Client($server, array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'timeout' => 30)); $client->setParameterGet($parameters); // debugMessage($client); // debugMessage(getClientUrl($client)); exit; $smsresult = array(1 => '', 2 => ''); if ($sendsms) { try { //$response = $client->request(); //$body = $response->getBody(); // debugMessage($body); $body = 'SUBMIT_SUCCESS | 53d5cc68-6522-4562-1db4-bee4ae855484'; $msgarray = explode('|', trim($body)); if (!isArrayKeyAnEmptyString('0', $msgarray)) { $smsresult[1] = trim($msgarray[0]); } else { $smsresult[1] = ''; } if (!isArrayKeyAnEmptyString('1', $msgarray)) { $smsresult[2] = trim($msgarray[1]); } else { $smsresult[2] = ''; } // check no of receipients $countphones = count(explode(',', trim($phone))); // save to outbox too $query = "INSERT INTO outbox (phone, msg, source, resultcode, smsid, datecreated, createdby, messageid, msgcount) values ('" . $phone . "', '" . $message . "', '" . $parameters['sender'] . "', '" . $smsresult[1] . "', '" . $smsresult[2] . "', '" . getCurrentMysqlTimestamp() . "', '" . $session->getVar('userid') . "', '" . $msgid . "', '" . $countphones . "') "; // debugMessage($query); $conn = Doctrine_Manager::connection(); $conn->execute($query); return $smsresult; } catch (Zend_Http_Client_Adapter_Exception $e) { # error handling $message = "Error in sending Message: " . $e->getMessage(); debugMessage($message); return array(1 => '', 2 => ''); } } // debugMessage($smsresult); exit; return array(1 => '', 2 => ''); }
function approveAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $session = SessionWrapper::getInstance(); $config = Zend_Registry::get("config"); $this->_translate = Zend_Registry::get("translate"); $formvalues = $this->_getAllParams(); debugMessage($formvalues); // exit; if (!isArrayKeyAnEmptyString('id', $formvalues)) { if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet = new Timesheet(); $timesheet->populate(decode($formvalues['id'])); $timesheet->setStatus($formvalues['status']); if (!isEmptyString($timesheet->getDateIn()) && !isEmptyString($timesheet->getDateOut())) { $timesheet->setHours($timesheet->getComputedHours()); } $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); if (!isArrayKeyAnEmptyString('reason', $formvalues)) { $timesheet->setComments("<br/>Rejected with remarks: " . $formvalues['reason']); } // debugMessage($timesheet->toArray()); try { if ($timesheet->save()) { $session->setVar(SUCCESS_MESSAGE, "Successfully Approved"); } $timesheet->afterApprove(); } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } // exit; if (!isArrayKeyAnEmptyString('ids', $formvalues)) { $idsarray = array_remove_empty(explode(',', $formvalues['ids'])); // debugMessage($idsarray); if (isArrayKeyAnEmptyString('status', $formvalues)) { $formvalues['status'] = 3; } $timesheet_collection = new Doctrine_Collection(Doctrine_Core::getTable("Timesheet")); if (count($idsarray) > 0) { $hrs = 0; foreach ($idsarray as $key => $id) { $timesheet = new Timesheet(); $timesheet->populate($id); $timesheet->setStatus($formvalues['status']); $timesheet->setHours($timesheet->getComputedHours()); // debugMessage($timesheet->getComputedHours()); $timesheet->setDateApproved(DEFAULT_DATETIME); $timesheet->setApprovedByID($session->getVar('userid')); $timesheet_collection->add($timesheet); // debugMessage($timesheet->toArray()); } try { if ($timesheet_collection->save()) { $msg = "Successfully Approved"; if ($formvalues['status'] == 4) { $msg = "Successfully Rejected"; } $session->setVar(SUCCESS_MESSAGE, $msg); foreach ($timesheet_collection as $timesheet) { $timesheet->afterApprove(); } } } catch (Exception $e) { $session->setVar(ERROR_MESSAGE, $e->getMessage()); } } } $this->_helper->redirector->gotoUrl(decode($this->_getParam(URL_SUCCESS))); }