Example #1
0
 /**
  * Returns id by name($value) from table
  *
  * @param  string $value
  * @return string
  */
 public function filter($value)
 {
     if ($value === null) {
         return null;
     }
     $select = $this->_table->select()->where($this->_field . ' = ?', $value);
     $row = $this->_table->fetchRow($select);
     if ($row !== null) {
         return $row[reset($this->_table->info(Zend_Db_Table::PRIMARY))];
     } else {
         return null;
     }
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see models/Sahara/Auth/Sahara_Auth_Session::setup()
  */
 public function setup()
 {
     $table = new Zend_Db_Table('users');
     $record = $table->fetchRow($table->select()->where('name = ?', $this->_authType->getUsername())->where('namespace = ?', $this->_config->institution));
     /* User name exists, so no need to create account. */
     if ($record) {
         return;
     }
     $table->insert(array('name' => $this->_authType->getUsername(), 'namespace' => $this->_config->institution, 'persona' => 'USER'));
 }
Example #3
0
 public static function getLastAccess($classroomId, $data)
 {
     $access = new Zend_Db_Table('content_access');
     $select = $access->select()->where('classroom_id = ?', $classroomId)->order('content_access.id DESC');
     $row = $access->fetchRow($select);
     if ($row) {
         return self::getPositionById($row->content_id, $data);
     }
     return 0;
 }
 public function getReceivers($pairs = false)
 {
     $triggersTable = new Zend_Db_Table('email_triggers_recipient');
     if ($pairs) {
         $select = $triggersTable->select();
         return $triggersTable->getAdapter()->fetchPairs($select);
     } else {
         return $triggersTable->fetchAll()->toArray();
     }
 }
Example #5
0
 public function indexAction()
 {
     $page = Zend_Filter::filterStatic($this->_getParam('page'), 'int');
     $query = Zend_Filter::filterStatic($this->_getParam('query'), 'alnum');
     $table = new Zend_Db_Table('course');
     $select = $table->select()->order('status');
     if ($query) {
         $select->where('name LIKE (?)', "%{$query}%");
     }
     $paginator = new Tri_Paginator($select, $page);
     $this->view->data = $paginator->getResult();
 }
 /**
  * Stores information about trusted/untrusted site for given user
  *
  * @param string $id user identity URL
  * @param string $site site URL
  * @param mixed $trusted trust data from extensions or just a boolean value
  * @return bool
  */
 public function addSite($id, $site, $trusted)
 {
     if (is_null($trusted)) {
         $this->_sitesTable->select()->where('site = ?', $site);
         $this->_sitesTable->delete($where);
         return true;
     }
     $row = $this->_sitesTable->createRow();
     $row->openid = $id;
     $row->site = $site;
     $row->time = date('Y-m-d H:i:s O');
     $row->trusted = serialize($trusted);
     $row->save();
     return true;
 }
Example #7
0
 private function _init()
 {
     global $logger;
     $oTable = new Zend_Db_Table('path');
     foreach ($oTable->fetchAll($oTable->select())->toArray() as $xt) {
         $this->_path[] = $xt['name'];
     }
     $oTable = new Zend_Db_Table('container');
     $t = array();
     foreach ($oTable->fetchAll($oTable->select())->toArray() as $xt) {
         $t[] = $xt['name'];
     }
     $this->_extensions = implode(',', $t);
     $logger->log('Valid extensions are : ' . $this->_extensions, Zend_Log::DEBUG);
 }
Example #8
0
 /**
  * Action index.
  *
  * @return void
  */
 public function indexAction()
 {
     $page = Zend_Filter::filterStatic($this->_getParam('page'), 'int');
     $query = $this->_getParam('query');
     $table = new Zend_Db_Table('user');
     $select = $table->select()->order('name');
     if ($query) {
         $parts = explode(' ', $query);
         foreach ($parts as $part) {
             $select->where('name LIKE ?', "%{$part}%");
         }
         $select->orWhere('email LIKE ?', "%{$query}%");
     }
     $paginator = new Tri_Paginator($select, $page);
     $this->view->data = $paginator->getResult();
 }
Example #9
0
 /**
  * Action index.
  *
  * @return void
  */
 public function indexAction()
 {
     $user = Zend_Auth::getInstance()->getIdentity();
     if ('student' == $user->role) {
         $this->_redirect('selection-process/index/view/user/' . $user->id);
     }
     $page = Zend_Filter::filterStatic($this->_getParam('page'), 'int');
     $query = Zend_Filter::filterStatic($this->_getParam('query'), 'alnum');
     $table = new Zend_Db_Table('selection_process');
     $select = $table->select()->order('end DESC');
     if ($query) {
         $select->where('name LIKE (?)', "%{$query}%");
     }
     $paginator = new Tri_Paginator($select, $page);
     $this->view->data = $paginator->getResult();
 }
Example #10
0
 /**
  * retourne tous les parametres
  *
  * @return Settings
  */
 public function load()
 {
     global $logger;
     $this->_init();
     foreach ($this->_tables as $holder => $table) {
         $oTable = new Zend_Db_Table($table);
         $xt = array();
         foreach ($oTable->fetchAll($oTable->select()->order('id ASC'))->toArray() as $o) {
             $xsetting = new Setting();
             $xsetting->name = $o['name'];
             $xsetting->id = $o['id'];
             $xt[] = $xsetting;
         }
         $t[$holder] = $xt;
     }
     $s = new Settings($this->_description, $t[0], $t[1], $t[2], $t[3], $t[4], $t[5], $t[6], $t[7], $t[8]);
     return $s;
 }
Example #11
0
 /**
  * Получаем информацию о разделе
  *
  * @param int $item_id
  * @param int $menu_id
  * 
  * @return array
  */
 public function getSection($item_id, $menu_id)
 {
     $menu = $this->getMenu($menu_id);
     if ($menu->type == 'router') {
         // получаем разделы меню привязонного к маршруту
         $item = $this->_modelItems->fetchRow($this->_modelItems->select()->where('route_id = ?', $item_id)->where('menu_id = ?', $menu->menu_id));
         $itemRoute = Modules_Router_Model_Router::getInstance()->getItem($item_id);
         $return = $item ? $item->toArray() + $itemRoute : $itemRoute;
         $return['type'] = 'router';
         $return['parent_id'] = $itemRoute['parent_route_id'];
         $return['name_route'] = $itemRoute['name'];
         $return['name'] = $item['name'] ? $item['name'] : $itemRoute['name'];
         unset($return['parent_route_id'], $return['childs']);
     } else {
         $return = $this->_modelItems->fetchRow($this->_modelItems->select()->where('item_id = ?', $item_id))->toArray();
     }
     return $return;
 }
Example #12
0
 /**
  * Returns true if the user can be authenticaed using the
  * supplied credential. The tests for success with this authentication
  * type are:
  * <ol>
  * 	<li>The user must exist.</li>
  * 	<li>The user must have database authorisation enabled
  * 	(auth_allowed = true).</li>
  *  <li>The password must match the record password.</li>
  * </ol>
  *
  * @return boolean true if the user is authenticated
  * @see models/Sahara/Auth/Sahara_Auth_Type::authenticate()
  */
 public function authenticate()
 {
     $table = new Zend_Db_Table('users');
     $this->_record = $table->fetchRow($table->select()->where('name = ?', $this->_user)->where('namespace = ?', $this->_config->institution));
     /* 1) User must exist. */
     if ($this->_record == null) {
         return false;
     }
     $allowed = (int) $this->_record->auth_allowed;
     if (is_string($allowed)) {
         $allowed = (int) $allowed && true;
     }
     /* 2) Authorisation must be enabled. */
     if (!$allowed) {
         return false;
     }
     /* 3) Passwords must match. */
     return $this->_record->password == sha1($this->_pass);
 }
Example #13
0
 /**
  * Get comments for a page
  * 
  * @param  string  $bookName
  * @param  string  $pageName
  * @param  boolean $approvedOnly
  * @return array
  */
 public static function getCommentsForPage($bookName, $pageName, $approvedOnly = true)
 {
     $table = new Zend_Db_Table('comments');
     $select = $table->select()->where('page = ?', $pageName)->where('book = ?', $bookName)->order('created_at DESC');
     if ($approvedOnly) {
         $select->where('flags & ?', self::FLAG_APPROVED);
     }
     $stmt = $select->query();
     $comments = array();
     while ($cData = $stmt->fetch(Zend_Db::FETCH_ASSOC)) {
         $comment = new self($cData);
         $comment->_id = $cData['id'];
         $comments[] = $comment;
     }
     return $comments;
 }
Example #14
0
 public function fetchUserFriends($id)
 {
     $id = (int) $id;
     $table = new Zend_Db_Table('friends');
     $select = $table->select()->setIntegrityCheck(false);
     $select->from(array('f' => 'friends'), array('f.id_friend'));
     $select->where('f.id_user = ?', $id);
     $select->joinInner(array('u' => 'users'), 'f.id_friend = u.id', array('u.username'));
     return $table->fetchAll($select)->toArray();
 }
 public function accountAction()
 {
     // Leave if not ready
     if (empty($this->_session->mysql)) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'db-info'));
     }
     $this->view->form = $form = new Install_Form_Account();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Check passwords match
     $values = $form->getValues();
     if ($values['password'] != $values['password_conf']) {
         $form->addError('Passwords must match.');
         return;
     }
     // Create account
     // Connect again
     try {
         $config = $this->dbFormToConfig($this->_session->mysql);
         // Connect!
         $adapter = Zend_Db::factory($config['adapter'], $config['params']);
         $adapter->getServerVersion();
     } catch (Exception $e) {
         $form->addError('Adapter Error: ' . $e->getMessage());
         //$this->view->code = 1;
         //$this->view->error = 'Adapter Error: ' . $e->getMessage();
         return;
     }
     // attempt to disable strict mode
     try {
         $adapter->query("SET SQL_MODE = ''");
     } catch (Exception $e) {
     }
     try {
         // Preprocess
         $settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings'));
         $usersTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_users'));
         $levelTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_authorization_levels'));
         // Get static salt
         $staticSalt = $settingsTable->find('core.secret')->current();
         if (is_object($staticSalt)) {
             $staticSalt = $staticSalt->value;
         } else {
             if (!is_string($staticSalt)) {
                 $staticSalt = '';
             }
         }
         // Get superadmin level
         $superAdminLevel = $levelTable->fetchRow($levelTable->select()->where('flag = ?', 'superadmin'));
         if (is_object($superAdminLevel)) {
             $superAdminLevel = $superAdminLevel->level_id;
         } else {
             $superAdminLevel = 1;
         }
         // Temporarily save pw
         $originalPassword = $values['password'];
         // Adjust values
         $values['salt'] = (string) rand(1000000, 9999999);
         $values['password'] = md5($staticSalt . $values['password'] . $values['salt']);
         $values['level_id'] = $superAdminLevel;
         $values['enabled'] = 1;
         $values['verified'] = 1;
         $values['creation_date'] = date('Y-m-d H:i:s');
         $values['creation_ip'] = ip2long($_SERVER['REMOTE_ADDR']);
         $values['displayname'] = $values['username'];
         // Try to write info to config/auth.php
         if (!$this->_writeAuthToFile($values['email'], 'seiran', $originalPassword)) {
             throw new Exception('Unable to write Auth to File');
         }
         // Insert
         $row = $usersTable->createRow();
         $row->setFromArray($values);
         $row->save();
         // First Signup Increment
         // Engine_Api::_()->getDbtable('statistics', 'core')->increment('user.creations');
         // Validate password
         if ($row->password != md5($staticSalt . $originalPassword . $row->salt)) {
             throw new Engine_Exception('Error creating password');
         }
         // Log the user into the intaller
         $auth = Zend_Registry::get('Zend_Auth');
         $auth->getStorage()->write($row->user_id);
         // Try to log the user into socialengine
         // Note: nasty hack
         try {
             $mainSessionName = 'PHPSESSID';
             if (empty($_COOKIE[$mainSessionName])) {
                 $mainSessionId = md5(mt_rand(0, time()) . serialize($_SERVER));
                 setcookie($mainSessionName, $mainSessionId, null, dirname($this->view->baseUrl()), $_SERVER['HTTP_HOST'], false, false);
             } else {
                 $mainSessionId = $_COOKIE[$mainSessionName];
             }
             $adapter->insert('engine4_core_session', array('id' => $mainSessionId, 'modified' => time(), 'lifetime' => 86400, 'data' => 'Zend_Auth|' . serialize(array('storage' => $row->user_id))));
         } catch (Exception $e) {
             // Silence
             if (APPLICATION_ENV == 'development') {
                 echo $e->__toString();
             }
         }
         // Update some other stuff
         $settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings'));
         // Save site name
         $row = $settingsTable->find('core.general.site.title')->current();
         if (null === $row) {
             $row = $settingsTable->createRow();
             $row->name = 'core.general.site.title';
         }
         $row->value = $values['site_title'];
         $row->save();
         // Save email
         $row = $settingsTable->find('core.license.email')->current();
         if (null === $row) {
             $row = $settingsTable->createRow();
             $row->name = 'core.license.email';
         }
         if ($row->value != '*****@*****.**') {
             $row->value = $values['email'];
             $row->save();
         }
         // Update profile fields
         try {
             $fieldValuesTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_user_fields_values'));
             $fieldValuesTable->insert(array('item_id' => 1, 'field_id' => 1, 'index' => 0, 'value' => 1));
         } catch (Exception $e) {
         }
     } catch (Exception $e) {
         $form->addError('Error: ' . $e->getMessage());
         return;
     }
     // Redirect if successful
     return $this->_helper->redirector->gotoRoute(array('action' => 'complete'));
 }
Example #16
0
 /**
  * @description save vote into a DB and forwards to the next action
  * @param array $forward where to go after action is over
  * @return void
  * @author Se#
  * @version 0.0.1
  */
 public function _actionDefault()
 {
     // define if there are required fields
     if (!isset(self::$_info['params']['objectId']) || !isset(self::$_info['params']['objectTable'])) {
         self::$_info['controller']->_redirect('/');
     }
     $params = self::$_info['params'];
     // for the more comfort
     $session = new Zend_Session_Namespace('evil-votes');
     // get session
     $voteTable = new Zend_Db_Table(Evil_DB::scope2table('vote'));
     // get table; TODO: get name from a config
     // If there are votes and count for the current object, than get last mark from it
     if (isset($session->votes) && isset($session->votes[$params['objectId'] . $params['objectTable']])) {
         $params['mark'] += $session->votes[$params['objectId'] . $params['objectTable']];
     } else {
         // otherwise get last mark from a DB
         $vote = $voteTable->fetchRow($voteTable->select()->where('objectId=?', $params['objectId'])->where('objectTable=?', $params['objectTable'])->order('ctime DESC'));
         $params['mark'] += $vote ? is_object($vote) ? $vote->mark : $vote['mark'] : 0;
     }
     $params['ctime'] = time();
     // set creation time
     // insert data, clean off system params such as controller, action, etc
     $voteTable->insert($this->_cleanParams($params));
     if (isset($session->votes)) {
         // Save current mark into session
         $session->votes[$params['objectId'] . $params['objectTable']] = $params['mark'];
     }
     // define where should forward
     $forward = isset(self::$_info['controller']->selfConfig['vote']['forward']) ? self::$_info['controller']->selfConfig['vote']['forward'] : array('list', self::$_info['controllerName'], null, array());
     // forward
     call_user_func_array(array(self::$_info['controller'], '_forward'), $forward);
     //self::$_info['controller']->_forward($forward[0], $forward[1], $forward[2], $forward[3]);
 }
Example #17
0
 public function select()
 {
     $select = parent::select();
     $select->where('namespace = ?', $this->_namespace);
     return $select;
 }
Example #18
0
 public static function getFieldById($tablename, $id, $getField = 'Code')
 {
     $db = new Zend_Db_Table($tablename);
     $rowSet = $db->select()->where("id =?", $id);
     $result = $db->fetchRow($rowSet);
     if ($result) {
         $result = $result->toArray();
     }
     if ($getField) {
         return $result[$getField] ? $result[$getField] : $result['Code'];
     } else {
         return $result['Code'];
     }
 }
Example #19
0
 protected function _authDb($identity, $credential)
 {
     $auth = Zend_Registry::get('Zend_Auth');
     // Check if it's possible to authenticate
     if (!Zend_Registry::isRegistered('Zend_Db') || !($db = Zend_Registry::get('Zend_Db')) instanceof Zend_Db_Adapter_Abstract) {
         throw new Engine_Exception('Unable to authenticate, no database connection present');
     }
     // Make user table and level table
     try {
         $userTable = new Zend_Db_Table(array('db' => $db, 'name' => 'engine4_users'));
         $userTable->info();
         // Forces check on table existence
         $levelTable = new Zend_Db_Table(array('db' => $db, 'name' => 'engine4_authorization_levels'));
         $levelTable->info();
         // Forces check on table existence
         $settingsTable = new Zend_Db_Table(array('db' => $db, 'name' => 'engine4_core_settings'));
         $settingsTable->info();
         // Forces check on table existence
     } catch (Exception $e) {
         throw new Engine_Exception('Unable to authenticate, missing database tables');
     }
     // Try to authenticate
     try {
         // Get static salt
         $staticSalt = $settingsTable->find('core.secret')->current();
         if (is_object($staticSalt)) {
             $staticSalt = $staticSalt->value;
         } else {
             $staticSalt = '';
         }
         // Get superadmin levels
         $saLevels = $levelTable->select()->where('flag = ?', 'superadmin')->query()->fetchAll();
         $saLevelIds = array();
         foreach ((array) $saLevels as $dat) {
             if (is_numeric($dat['level_id'])) {
                 $saLevelIds[] = $dat['level_id'];
             }
         }
         if (empty($saLevelIds)) {
             return $form->addError('No admin levels');
         }
         $saLevelStr = "'" . join("','", $saLevelIds) . "'";
         // Authenticate
         $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'engine4_users', 'email', 'password', "MD5(CONCAT('" . $staticSalt . "', ?, salt)) && `level_id` IN({$saLevelStr})");
         $authAdapter->setIdentity($identity)->setCredential($credential);
         $authResult = $auth->authenticate($authAdapter);
     } catch (Exception $e) {
         throw new Engine_Exception('An error occurred');
     }
     // Check result
     $authCode = $authResult->getCode();
     if ($authCode != Zend_Auth_Result::SUCCESS) {
         return false;
     }
     return true;
 }
Example #20
0
 /**
  * Get total number of unread messages for an user_id
  *
  * @param user_id
  */
 public function getUnreadCount($user_id)
 {
     if (!$user_id) {
         return null;
     }
     $messages_table = new Zend_Db_Table('messages');
     $subselect = $messages_table->select()->setIntegrityCheck(false)->from(array('m' => 'messages'))->join(array('t' => 'threads'), 'm.thread_id = t.id', array('unread'))->where('last_speaker != ? AND t.user_from = ? AND t.deleted_from = 0', $user_id, $user_id)->orWhere('last_speaker != ? AND t.user_to = ? AND t.deleted_to = 0', $user_id, $user_id)->group('thread_id');
     $readConf = new Zend_Config_Ini(APPLICATION_PATH . '/config/nolotiro.ini', 'production');
     $dbAdapter = Zend_Db::factory($readConf->resources->db);
     $select = $dbAdapter->select()->from(array('tmp' => $subselect), array('unread_count' => 'sum(unread)'));
     $result = $dbAdapter->fetchOne($select);
     return !$result ? 0 : $result;
 }
Example #21
0
 public function getAdListAllHome($ad_type)
 {
     $table = new Zend_Db_Table('ads');
     $select = $table->select()->setIntegrityCheck(false);
     $select->from(array('a' => 'ads'), array('a.*'));
     $select->joinLeft(array('c' => 'commentsAdCount'), 'a.id = c.id_comment', array('c.count as comments_count'));
     $select->joinLeft(array('r' => 'readedAdCount'), 'a.id = r.id_ad', array('r.counter as readings_count'));
     $select->join(array('u' => 'users'), 'a.user_owner = u.id', array('u.username'));
     //show only if user is active and not locked
     $select->where('u.active = ?', 1);
     $select->where('u.locked = ?', 0);
     $select->where('a.type = ?', $ad_type);
     $select->where('a.status = ?', 'available');
     $select->order('a.date_created DESC');
     $select->limit(20);
     $result = $table->fetchAll($select)->toArray();
     return $result;
 }
Example #22
0
 public function setup()
 {
     /* Load the user's record. */
     $table = new Zend_Db_Table('users');
     $record = $table->fetchRow($table->select()->where('name = ?', $this->_authType->getUsername())->where('namespace = ?', $this->_config->institution));
     if (!$record) {
         $this->_logger->warn('User ' . $this->_authType->getUsername() . ' does not exist so cannot update their ' . ' details.');
         return;
     }
     /* Load the user details. */
     $fn = $this->_getAuthProperty($this->_fnFields);
     $sn = $this->_getAuthProperty($this->_snFields);
     $email = $this->_getAuthProperty($this->_emailFields);
     /* Compare and store. */
     $needsSave = false;
     if ($fn && $record->first_name != $fn) {
         $record->first_name = $fn;
         $needsSave = true;
     }
     if ($sn && $record->last_name != $sn) {
         $record->last_name = $sn;
         $needsSave = true;
     }
     if ($email && $record->email != $email) {
         $record->email = $email;
         $needsSave = true;
     }
     if ($needsSave) {
         $record->save();
     }
 }
Example #23
0
 /**
  * Returns an instance of a Zend_Db_Table_Select object.
  *
  * @param bool $withFromPart Whether or not to include the from part of
  *  the select based on the table
  * @return Zend_Db_Table_Select
  * @see http://framework.zend.com/manual/1.12/en/zend.db.select.html Zend_Db_Select
  */
 public function select($withFromPart = parent::SELECT_WITHOUT_FROM_PART)
 {
     return parent::select($withFromPart)->setIntegrityCheck(false);
 }
Example #24
0
 public function indexAction()
 {
     $contact = new Zend_Db_Table('contacts');
     $query = $contact->select()->order('name');
     $this->view->contacts = $contact->fetchAll($query);
 }