/**
  * Returns a new UcPermissionPageMatchesQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   UcPermissionPageMatchesQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return UcPermissionPageMatchesQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof UcPermissionPageMatchesQuery) {
         return $criteria;
     }
     $query = new UcPermissionPageMatchesQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(UcPermissionPageMatchesPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = UcPermissionPageMatchesQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Example #3
0
function securePage($uri)
{
    //Separate document name from uri
    $tokens = explode('/', $uri);
    $page = $tokens[sizeof($tokens) - 1];
    global $loggedInUser, $master_account;
    //retrieve page details
    $query = UcPagesQuery::create()->limit(1)->findByPage($page);
    foreach ($query as $securePage) {
        $pageDetails = array('id' => $securePage->getId(), 'page' => $securePage->getPage(), 'private' => $securePage->getIsPrivate());
    }
    //If page does not exist in DB, allow access
    if (empty($pageDetails)) {
        return false;
    } elseif ($pageDetails['private'] == 0) {
        return true;
    } elseif (!isUserLoggedIn()) {
        header("Location: " . str_replace('index.php/', '', site_url('login')));
        return false;
    } else {
        //Retrieve list of permission levels with access to page
        $query = UcPermissionPageMatchesQuery::create()->findByPageId($pageDetails['id']);
        foreach ($query as $permission) {
            $pagePermissions[] = $permission->getPermissionId();
        }
        //Check if user's permission levels allow access to page
        if ($loggedInUser->checkPermission($pagePermissions)) {
            return true;
        } elseif ($loggedInUser->user_id == $master_account) {
            return true;
        } else {
            header("Location: " . str_replace('index.php/', '', site_url('no_page_found')));
            return false;
        }
    }
}