Example #1
0
 /**
  * @return App_Log
  * Enter description here ...
  */
 static function get()
 {
     if (self::$_instran == null) {
         self::$_instran = new App_Log();
     }
     return self::$_instran;
 }
Example #2
0
 /**
  * errorAction() is the action that will be called by the "ErrorHandler" 
  * plugin.  When an error/exception has been encountered
  * in a ZF MVC application (assuming the ErrorHandler has not been disabled
  * in your bootstrap) - the Errorhandler will set the next dispatchable 
  * action to come here.  This is the "default" module, "error" controller, 
  * specifically, the "error" action.  These options are configurable, see 
  * {@link http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standar
  *
  * @return void
  */
 public function errorAction()
 {
     $errors = $this->_getParam('error_handler');
     switch ($errors->type) {
         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';
             break;
         default:
             // application error
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->message = 'Application error';
             break;
     }
     App_Log::get()->debug($this, $errors->exception->getMessage());
     $this->view->exception = $errors->exception;
     $this->view->request = $errors->request;
 }
Example #3
0
 protected function _submitForm(App_Form $form, $request, $id = '', $nextPage = 'index')
 {
     $this->_setForm($form);
     App_Log::get()->debug($this, "begin _submitForm: id[{$id}] nextPage[{$nextPage}]");
     if ($request->getPost()) {
         if ($form->isValid($request->getPost())) {
             $isValid = true;
             if ($isValid) {
                 try {
                     if ($id == null) {
                         $info = 7;
                     } else {
                         $info = 8;
                     }
                     if ($this->_section != '') {
                         $form->addParam('secid', $this->_section);
                     }
                     // if ($this->_catigory != '') {
                     //     $form->addParam( 'catid', $this->_catigory );
                     //  }
                     $lastId = $form->save($id);
                     $data['id'] = $lastId;
                     if ($form->isInsearted()) {
                         $this->_callBackAffterInsert($form, $data);
                     } elseif ($form->isUpdated()) {
                         $this->_callBackAffterUpdate($form, $data);
                     }
                     App_Log::get()->debug($this, "affter save: lastId[{$lastId}] ");
                     if (trim($id) == '') {
                         $id = $lastId;
                     }
                     $url = $this->view->url($nextPage);
                     $this->_helper->redirector($nextPage, null, null, array('id' => $id, 'info' => $info));
                 } catch (Zend_Db_Exception $e) {
                     $this->view->infocode = 10;
                     App_Log::get()->debug($this, $e->getMessage());
                     echo $e->getMessage();
                 }
             }
         }
     }
 }
Example #4
0
 public function delete($where = null)
 {
     $cache_dir = PRIVATE_PATH . '/data/cache/' . $this->getModelName();
     App_Util::remove_dir($cache_dir);
     App_Util::remove_dir(CACHE_OUTPUT_DIR);
     if ($where == null) {
         $pkcol = $this->getPkColumn();
         $pkpop = $this->getPKName();
         $pkval = $this->{$pkpop};
         $where = "{$pkcol} = '{$pkval}'";
     }
     $this->getMapper()->delete($where, $this);
     $this->_handleAffterDeleted($this);
     if ("Sys_Model_AppLog" != $this->getModelName()) {
         $models = explode("_Model_", $this->getModelName());
         $modelName = strtolower($models[1]);
         $id = $this->getMapper()->getLastInsertId();
         $message = "deleted {$modelName} {$pkcol}:{$pkval}";
         App_Log::get()->addlog(array("remark" => $where, "message" => $message, "activity" => "delete", "refType" => $this->getModelName(), "refId" => $id));
     }
     return $this;
 }
Example #5
0
 /**
  * Executes call to httpBl Api
  * @param $ip
  * @return string
  */
 private function _httpBlInfo($ip)
 {
     if (isset($this->_cache[$ip])) {
         return $this->_cache[$ip];
     }
     // revert ip
     $ipPieces = explode('.', $ip);
     $ipPieces = array_reverse($ipPieces);
     $ip = implode('.', $ipPieces);
     $request = "{$this->_accessKey}.{$ip}.dnsbl.httpbl.org";
     $result = gethostbyname($request);
     if ($request == $result) {
         // no info
         $this->_cache[$ip] = false;
         return false;
     }
     $this->_cache[$ip] = $result;
     $octets = explode('.', $result);
     if (127 != $octets[0]) {
         App_Log::errorLog("Can't get ip info for request {$request} result {$result}", CLogger::LEVEL_ERROR);
         return false;
     }
     return $result;
 }
Example #6
0
 /**
  * Find a guestbook entry by id
  *
  * @param  int $id
  * @return void
  */
 public function find($id, App_Model_Abstract &$model)
 {
     try {
         $modelName = $model->getModelName();
         if (CACHE_DB_ENABLED) {
             $cache_dir = PRIVATE_PATH . '/data/cache/' . $model->getModelName();
             @mkdir($cache_dir, 0777, true);
             $backendOptions = array('cache_dir' => $cache_dir);
             $frontendOptions = array('lifetime' => 7200, 'automatic_serialization' => true);
             $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
         }
         $config = $this->getModelConfig();
         $pk = 'id';
         foreach ($config->prop as $prop) {
             //หา PK
             if ($prop->pk) {
                 $pk = $prop->column;
                 break;
             }
         }
         App_Log::get()->debug($this, "BEGIN find");
         $row = false;
         $cacheId = $model->getModelName() . "_" . $id;
         if (CACHE_DB_ENABLED) {
             $row = $cache->load($cacheId);
         }
         if ($row === false) {
             if (isset($config->config->sql)) {
                 $sql = $config->config->sql;
                 $sqlselect = " SELECT * FROM ( {$sql} )  tttt  WHERE {$pk} LIKE ? ";
                 $db = App_Env::getDb();
                 $row = $result = $db->fetchRow($sqlselect, array($id));
             } else {
                 $result = $this->getDbTable()->find($id);
                 $row = $result->current();
             }
             App_Log::get()->debug($this, "result");
             if (0 == count($result)) {
                 App_Log::get()->debug($this, "count result = 0");
                 return false;
             }
             App_Log::get()->debug($this, "count result > 0");
             if (CACHE_DB_ENABLED) {
                 $cache->save($row, $cacheId);
             }
         }
         $model = $this->bindEntry($model, $row);
         App_Log::get()->debug($this, "end for each");
         return true;
     } catch (Exception $e) {
         App_Log::get()->debug($this, "Exception" . $e->getMessage());
         //echo $e->getMessage ();
     }
 }
Example #7
0
 function send()
 {
     //print_r($this->_templete_params);
     try {
         $html = $this->getBodyContent();
         $mail = new Zend_Mail('utf-8');
         $mail->clearDefaultFrom();
         $mail->setBodyHtml($html);
         $mail->addHeader('mailedby', WEB_HOST);
         // $mail->addHeader('X-MailGenerator', 'MyCoolApplication');
         $mail->setFrom(App_Env::getSystemEmail(), App_Env::getSystemEmailFrom());
         $this->setSender(App_Env::getSystemEmail());
         foreach ($this->_to as $email) {
             $mail->addTo($email);
         }
         $this->addBcc(App_Env::getBccEmail());
         if (count($this->_bcc) > 0) {
             foreach ($this->_bcc as $email) {
                 $mail->addBcc($email);
             }
         }
         if ($this->getTemplateId() == Sys_Model_Template::EMAIL_NEW_ISSUE) {
             $this->_subject = str_replace("[ISSUE_NUMBER]", $this->getParam("ISSUE_NUMBER"), $this->_subject);
         } elseif ($this->getTemplateId() == Sys_Model_Template::EMAIL_REPLY_ISSUE) {
             $this->_subject = str_replace("[ISSUE_NUMBER]", $this->getParam("ISSUE_NUMBER"), $this->_subject);
         }
         $subject = $this->_subject;
         $mail->setSubject($this->_subject);
         $log = App_Log::get()->maillog($this);
         // บวก link
         $id = $log->id;
         $skey = $log->skey;
         $sid = base64_encode("{$id}&{$skey}&" . join(",", $this->_to));
         $onlineurl = WEB_DOMAIN . "/e?sid={$sid}";
         $html = "If you are having trouble reading this email, <a href='{$onlineurl}'>read the online version </a>." . $html;
         $mail->setBodyHtml($html);
         $this->_mail = $mail;
         $mail->send();
         // ส่ง notify admin
         if ($this->_sendNotify and in_array($this->getTemplateId(), array(Sys_Model_Template::EMAIL_NEW_ISSUE, Sys_Model_Template::EMAIL_REPLY_ISSUE, Sys_Model_Template::EMAIL_ACCOUNT_INFO, Sys_Model_Template::EMAIL_INVOICE, Sys_Model_Template::EMAIL_PURCHASE_ORDER))) {
             $notifier = new App_Mail_Notifier();
             $notifier->setSubject($subject);
             $notifier->setMailURL($onlineurl);
             $notifier->setAdminURL($this->getAdminURL());
             $notifier->send();
         }
         //  echo "notify";
         // exit();
     } catch (Exception $e) {
         //	$this->view->stat = 'error';
         //	$this->view->msg = $e->getMessage ();
         echo "error";
         echo $e->getMessage();
         // throw new Exception($e->getMessage());
     }
 }
Example #8
0
 public function saveLanguageContent($lang = LANGUAGE, $newid = null)
 {
     $languagePop = $this->_model->getMapper()->getLanguageChangeAbleProperties();
     //print_r($languagePop);
     App_Log::get()->debug($this, '274 Begin save model Language' . "lang[{$lang}]   newid[{$newid}]");
     if (count($languagePop) > 0) {
         $pk = $this->_model->getPKName();
         $content = $this->getContent($lang, $newid);
         foreach ($languagePop as $methodName) {
             $content->{$methodName} = $this->_model->{$methodName};
             echo $content->{$methodName};
         }
         try {
             $content->save();
             App_Log::get()->debug($this, "297  save Language  complete id =  " . $content->id);
         } catch (Exception $e) {
             throw $e;
         }
     }
 }
Example #9
0
 public function testAction()
 {
     $request = $this->getRequest();
     if ($request->getPost()) {
         try {
             $file = new Cms_Model_File();
             $file->setName('sdfdsfdsf')->setPath('dsfdsf')->setThumbnailPath('sdfdsfdsfsdf')->setType('dsfdsfdsfsdf')->save();
             echo "1";
         } catch (Exception $e) {
             App_Log::get()->debug($this, $e->getMessage());
             echo $e->getMessage();
             echo "0";
         }
     }
 }
Example #10
0
 public function authentication($username, $password)
 {
     $session = $this->getSession();
     $user = new Sam_Model_Account();
     //echo ( $user->select ()->where ( 'loginid = ?', $username )->where ( 'pwd = ?', $password ) );
     $userLogon = $user->fetchRow($user->select()->where('loginid = ?', $username)->where('pwd = ?', $password));
     if ($userLogon == null) {
         //print_r($userLogon);
         //App_Log::get()->authenLog('',$username,(bool)$userLogon->master,'FAILURE','Login Id was not found or Password was not correct');
         return self::FAILURE;
     } elseif ($userLogon->getStatus() != 1) {
         App_Log::get()->authenLog('', $username, (bool) $userLogon->master, 'FAILURE', 'Your User Account has been disabled or expired');
         return self::FAILURE;
     } else {
         App_Env::setSession('userFullname', $userLogon->getFullname());
         //$_SESSION['SES_USER_FULLNAME'] = $userLogon->getFullname();
         App_Env::setSession('userEmail', $userLogon->getEmail());
         //$_SESSION['SES_USER_EMAIL'] = $userLogon->getEmail();
         App_Env::setSession('userId', $userLogon->id);
         App_Env::setSession('userGroupId', $userLogon->groupid);
         App_Env::setSession("userType", 'admin');
         App_Env::setSession("master", (bool) $userLogon->master);
         $this->setIdentity($userLogon->id);
         $session->isLoginSuccess = true;
         Sam_Acl::getInstance()->setUser($userLogon);
         App_Env::createUserTemporaryFolder();
         try {
             $userLogon->setLastlogin(new DateTime());
             $userLogon->save();
         } catch (Exception $e) {
         }
         App_Log::get()->authenLog('', $userLogon, (bool) $userLogon->master, 'SUCCESS', '');
         return self::SUCCESS;
     }
 }
Example #11
0
 protected function _submitForm2(App_Form $form, $request, $id = '', $nextPage = '')
 {
     //print_r($_POST);
     //$model = $form->getModel();
     //$this->_setForm ( $form,$modelName );
     $id = trim($id);
     App_Log::get()->debug($this, "begin _submitForm: id[{$id}] nextPage[{$nextPage}]");
     if ($request->getPost()) {
         $validateMessage = $this->_validateForm($form, $request->getPost());
         if (is_null($validateMessage)) {
             if ($form->isValid($request->getPost())) {
                 $isValid = true;
                 if ($isValid) {
                     try {
                         if ($id == null) {
                             $info = 7;
                         } else {
                             $info = 8;
                         }
                         if ($this->_section != '') {
                             $form->addParam('secid', $this->_section);
                         }
                         // if ($this->_catigory != '') {
                         //     $form->addParam( 'catid', $this->_catigory );
                         //  }
                         //echo $id;
                         //$model = $form->getModel();
                         if (method_exists($this->_model, 'setIsActive')) {
                             $form->addParam('IsActive', 1);
                         }
                         $lastId = $form->save($id);
                         //$lastId
                         //print_r($lastId);
                         //exit();
                         $data['id'] = $lastId;
                         if ($form->isInsearted()) {
                             //echo "isInsearted";
                             $this->_callBackAffterInsert($form, $data);
                         } elseif ($form->isUpdated()) {
                             $this->_callBackAffterUpdate($form, $data);
                         }
                         App_Log::get()->debug($this, "affter save: lastId[{$lastId}] ");
                         if (trim($id) == '') {
                             $id = $lastId;
                         }
                         //$url = $this->view->url ( $nextPage );
                         if ($nextPage == 'curentpage') {
                             $this->view->infocode = $info;
                         } else {
                             if ($nextPage == 'refresh-parent') {
                                 $this->view->jQuery()->onLoadCaptureStart();
                                 echo "\n\t\t\t\t\t\t\t\t window.opener.location.reload(true);\n                                 window.close();\n                                 ";
                                 $this->view->jQuery()->onLoadCaptureEnd();
                             } else {
                                 if ($nextPage != '') {
                                     //echo $id,"--",$lastId;
                                     if ($this->_request->getParam('mode', '') != 'window') {
                                         //$buttons[]=$this->view->zbutton(array('action'=>'index','label'=>'Back','params'=>$this->_userparam));
                                         $param = array_merge(array('id' => $id, 'info' => $info), $this->_userparam);
                                         // print_r($param); exit();
                                         $this->_helper->redirector($nextPage, null, null, $param);
                                     } else {
                                         $this->view->jQuery()->onLoadCaptureStart();
                                         echo "\n\t\t\t\t\t\t\t\t window.opener.location.reload(true);\n                                 window.close();\n                                 ";
                                         $this->view->jQuery()->onLoadCaptureEnd();
                                     }
                                 } else {
                                     $this->view->alert("กรุณากรอกข้อมูลในแบบฟอร์มให้ถูกต้อง และ บันทึกข้อมูลอีกครั้ง");
                                     $this->view->infocode = $info;
                                 }
                             }
                         }
                     } catch (Exception $e) {
                         $this->view->alert("เกิดปัญหาในการบันทึกข้อมูล ลองบันทึกข้อมูลอีกครั้ง");
                         $this->view->infocode = App_Env::sqlerror($e->getMessage());
                         App_Log::get()->debug($this, $e->getMessage());
                         //echo "aadddddddddd",$e->getMessage ();
                     }
                 }
             } else {
                 $errors = $form->getMessages();
                 $messages = array();
                 foreach ($errors as $element_name => $error) {
                     $element_messages = array();
                     foreach ($error as $elmessages) {
                         $element_messages[] = "{$elmessages}";
                     }
                     $messages[] = "{$element_name}:" . join(",", $element_messages);
                 }
                 $form_alert_message = join("<br/>", $messages);
                 $this->view->alert("กรุณากรอกข้อมูลในแบบฟอร์มให้ถูกต้อง และ บันทึกข้อมูลอีกครั้ง <br/>" . str_replace("'", "\\'", $form_alert_message));
             }
         } else {
             $this->view->alert($validateMessage);
         }
     } else {
         // $this->view->infocode = "no post data";
     }
 }