Exemplo n.º 1
0
 /**
  * Get message
  * @param
  * @return
  */
 function msg($key)
 {
     if (!empty($this->_msg[$key])) {
         return $this->_msg[$key];
     } else {
         return FrontEnd::getMsg($key);
     }
     return null;
 }
Exemplo n.º 2
0
 function upload()
 {
     #d($this);
     $res = $this->_upload();
     #d($res);
     if (is_array($res)) {
         $messages = $res['messages'];
         $res = $res['res'];
     }
     if ($res) {
         $this->getTable()->setN(FrontEnd::getMsg(array('upload', 'ok')), 'success');
     } else {
         $this->getTable()->setN(FrontEnd::getMsg(array('upload', 'fail')), 'errors');
         if (!empty($messages)) {
             foreach ($messages as $value) {
                 $this->getTable()->setN($value, 'errors');
             }
         }
     }
     return $res;
 }
Exemplo n.º 3
0
 function addComment($identityId)
 {
     $res = false;
     $form = new Form_Comment();
     $formData = Zend_Controller_Front::getInstance()->getRequest()->getPost();
     if ($form->isValid($formData)) {
         $uid = $form->getValue('user_id', 0);
         if ($identityId != $uid) {
             l($uid, __METHOD__ . ': $uid invalid!', Zend_Log::DEBUG);
             return false;
         }
         $data = $form->getValues();
         $data['dt'] = $data['tm'] = dateMySQL();
         l($data, __METHOD__ . ': $data', Zend_Log::DEBUG);
         $res = $this->createComment($data);
     } else {
         l($formData, __METHOD__ . ': INVALID_COMMENT::formData', Zend_Log::DEBUG);
         Zend_Registry::set('comment_error', FrontEnd::getMsg(array('comments', 'fail')));
     }
     return $res;
 }
Exemplo n.º 4
0
 /**
  * insert/update & upload
  */
 protected function _updateData($data = array(), $conf = null)
 {
     l($data, __METHOD__ . ' data');
     l($conf, __METHOD__ . ' conf');
     $row = $res = false;
     if (!empty($data['id'])) {
         $where = $this->getAdapter()->quoteInto('id = ?', $data['id']);
         $res = $this->update($data, $where);
         $row = $this->getById($data['id']);
         // NB! get updated row always!
     } else {
         if (!empty($conf['test'])) {
             $res = 1;
             //TEST!
         } else {
             $res = $this->_insertData($data);
         }
         if ($res) {
             $row = $this->getById($res);
         }
     }
     l($row->toArray(), __METHOD__ . ' row_as_array');
     $notify = isset($conf['notify']) ? $conf['notify'] : true;
     if ($notify) {
         if ($res) {
             $this->setN(FrontEnd::getMsg(array('update', 'ok')), 'success');
         } else {
             $this->setN(FrontEnd::getMsg(array('update', 'fail')), 'errors');
         }
     }
     #d($row);
     $upload = isset($conf['upload']) ? $conf['upload'] : true;
     if ($row && $upload) {
         if (FrontEnd::isUpload()) {
             $resu = $row->upload();
             #d($res);
             if ($resu) {
                 Zend_Registry::set('uploaded', $resu);
             } else {
                 $upload_critical = isset($conf['upload_critical']) ? $conf['upload_critical'] : false;
                 // todo: hide broken record!
                 if ($upload_critical) {
                     $row->flag_status = 0;
                     $row->save();
                     $res = false;
                 }
             }
         }
     }
     // particular post-update manipulations
     #d($row);
     if ($row) {
         $res = $row->_postUpdate();
     }
     l($res, __METHOD__ . ' RES');
     return $row;
 }
Exemplo n.º 5
0
 /**
  * Регистрация
  * @return
  */
 function registerAction()
 {
     if ($this->view->identity) {
         $this->_redirect('/');
     }
     if (!$this->userRegistrationAllowed) {
         return $this->_forward('login');
     }
     $this->textRow('register');
     $form = $this->getFormRegister();
     if ($this->getRequest()->isPost()) {
         $rawData = $this->getRequest()->getPost();
         l($rawData, __METHOD__ . ' rawData');
         if ($form->isValid($rawData)) {
             $v = $form->getValues();
             $row = $this->getRow('users', 'email = "' . $v['email'] . '" OR LCASE(username) = "' . strtolower($v['username']) . '"');
             if ($row) {
                 #$this->setN(FrontEnd::getMsg(array('auth', 'loginExists')), 'errors');
                 $this->view->notifyerr[] = FrontEnd::getMsg(array('auth', 'loginExists'));
             } else {
                 $data = $v;
                 $data['password'] = md5($v['password']);
                 $data['created'] = new Zend_Db_Expr('NOW()');
                 l($data, __METHOD__ . ' data');
                 $row = $this->users->createRow($data);
                 $res = $row->save();
                 l($res, __METHOD__ . ' save() res');
                 if ($res) {
                     if (isset($this->conf->auth->mailRegister)) {
                         $data['password'] = $v['password'];
                         Users::mailRegister($data);
                     }
                     #$this->setN(FrontEnd::getMsg(array('auth', 'regSuccess')));#$this->setContent('');
                     $this->view->notifymsg[] = FrontEnd::getMsg(array('auth', 'regSuccess'));
                     #d($this->view->notifymsg);
                     $this->view->done = true;
                 }
             }
         } else {
             $this->view->errors = $form->getMessages();
             #d($res);
             #$this->setN(FrontEnd::getMsg(array('form', 'errors')), 'errors');
             $this->view->notifyerr[] = FrontEnd::getMsg(array('form', 'errors'));
         }
         #$this->_redirect($this->view->requestUri);
     }
     $this->view->form = $form;
 }