Ejemplo n.º 1
0
 /**
  * PPI Mail Sending Functioin
  * @param array $p_aOptions The options for sending to the mail library
  * @uses $p_aOptions[subject, body, toaddr] are all mandatory.
  * @uses Options available are toname
  * @return boolean The result of the mail sending process
  */
 static function sendMail(array $p_aOptions)
 {
     $oConfig = PPI_Helper::getConfig();
     $oEmail = new PPI_Model_Email_Advanced();
     if (!isset($p_aOptions['subject'], $p_aOptions['body'], $p_aOptions['toaddr'])) {
         throw new PPI_Exception('Invalid parameters to sendMail');
     }
     $oEmail->Subject = $p_sSubject;
     if (isset($p_aOptions['fromaddr'], $p_aOptions['fromname'])) {
         $oEmail->SetFrom($p_aOptions['fromaddr'], $p_aOptions['fromname']);
     } elseif (isset($p_aOptions['fromaddr'])) {
         $oEmail->SetFrom($p_aOptions['fromaddr']);
     } else {
         $oEmail->SetFrom($oConfig->system->adminEmail, $oConfig->system->adminName);
     }
     if (isset($p_aOptions['toaddr'], $p_aOptions['toname'])) {
         $oEmail->AddAddress($p_aOptions['toaddr'], $p_aOptions['toname']);
     } elseif (isset($p_aOptions['toaddr'])) {
         $oEmail->AddAddress($p_aOptions['toaddr']);
     }
     if (isset($p_aOptions['altbody'])) {
         $oEmail->AltBody = $p_sMessage;
     }
     $oEmail->MsgHTML($p_aOptions['body']);
     // If the email sent successfully,
     return $oEmail->Send();
     // @todo - Log the email sending process.
 }
Ejemplo n.º 2
0
 function __construct(PDOStatement $statement)
 {
     // Config override for fetchmode. If it's a valid fetchmode then we override
     $oConfig = PPI_Helper::getConfig();
     if (isset($oConfig->db->fetchmode) && $oConfig->db->fetchmode != '' && array_key_exists($oConfig->db->fetchmode, $this->_fetchModes)) {
         $this->_fetchMode = $oConfig->db->fetchmode;
     }
     $this->_statement = $statement;
 }
Ejemplo n.º 3
0
 function putRecord(array $aData)
 {
     $oConfig = PPI_Helper::getConfig();
     // If its an insert
     if (!array_key_exists($this->_iTableIndex, $aData)) {
         $plainPass = $aData['password'];
         if (!array_key_exists($oConfig->system->usernameField, $aData)) {
             throw new PPI_Exception('Unable to locate username field when creating user');
         }
         $aData['active'] = isset($oConfig->system->defaultUserActive) && $oConfig->system->defaultUserActive != false ? 1 : 0;
         $aData['created'] = time();
         $aData['activation_code'] = base64_encode(time());
         // ----- Password Stuff ----
         if (isset($aData['salt'])) {
             $sSalt = $aData['salt'];
             unset($aData['salt']);
             // If no salt has been set then we get it from the config.
         } else {
             $sSalt = $oConfig->system->userAuthSalt;
         }
         if (empty($sSalt)) {
             throw new PPI_Exception('No salt found when trying to register user');
         }
         $aData['password'] = $this->encryptPassword($sSalt, $aData['password']);
         // If no role_id has been set, lets set it from the config.
         if (!isset($aData['role_id'])) {
             if (!isset($oConfig->system->defaultUserRole)) {
                 throw new PPI_Exception('Missing config value system.defaultUserRole');
             }
             $aData['role_id'] = PPI_Model_Helper::getRoleIDFromName($oConfig->system->defaultUserRole);
         }
     } else {
         //if password is being passed in for re-set, we need to encrypt it
         if (isset($aData['password'], $aData['salt'])) {
             $aData['password'] = $this->encryptPassword($aData['salt'], $aData['password']);
             unset($aData[$oConfig->system->usernameField]);
             unset($aData['salt']);
         }
     }
     return parent::putRecord($aData);
     // set the system log here
     // send acitvation email here
     //$oEmail = new PPI_Model_Email();
     /*$oEmail->setTemplate('User Registration', array(
     			'site_name' => $oConfig->site_name,
     			'username' 	=> $aData[$oConfig->usernameField],
     			'password' 	=> $plainPass
     		))->sendMail();*/
 }
Ejemplo n.º 4
0
 /**
  * Returns an array of role_id => role_type of all the roles defined
  *
  * @return array
  */
 static function getRoles()
 {
     $oConfig = PPI_Helper::getConfig();
     if (isset($oConfig->user->roleMappingService) && $oConfig->user->roleMappingService == 'database') {
         $oUser = new APP_Model_User_Role();
         $aRoles = $oUser->getList()->fetchAll();
         $aRetRoles = array();
         foreach ($aRoles as $aRole) {
             $aRetRoles[$aRole['name']] = $aRole['id'];
         }
         return $aRetRoles;
     } else {
         return $oConfig->system->roleMapping->toArray();
     }
 }
Ejemplo n.º 5
0
 /**
  * Initialise the router and start grabbing routes
  *
  * @return void
  */
 function init()
 {
     include_once $this->getRoutingFile();
     $uri = str_replace(PPI_Helper::getConfig()->system->base_url, '/', PPI_Helper::getFullUrl());
     $route = $uri;
     // Loop through the route array looking for wild-cards
     foreach ($routes as $key => $val) {
         // Convert wild-cards to RegEx
         $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key);
         // Does the RegEx match?
         if (preg_match('#^' . $key . '$#', $uri)) {
             // Do we have a back-reference?
             if (strpos($val, '$') !== false && strpos($key, '(') !== false) {
                 $val = preg_replace('#^' . $key . '$#', $val, $uri);
             }
             $route = $val;
             break;
         }
     }
     $this->setMatchedRoute($route);
 }
Ejemplo n.º 6
0
 function getTemplateExtension()
 {
     $oConfig = PPI_Helper::getConfig();
     return !empty($oConfig->layout->rendererExt) ? $oConfig->layout->rendererExt : '.html';
 }
Ejemplo n.º 7
0
 /**
  * PPI_Controller::getConfig()
  * Returns the PPI_Config object
  * @return object
  */
 protected function getConfig()
 {
     return PPI_Helper::getConfig();
 }
Ejemplo n.º 8
0
 /**
  * The constructor
  */
 function __construct()
 {
     $this->_config = PPI_Helper::getConfig();
     $this->_input = PPI_Helper::getInput();
     $this->_fullUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . $_SERVER['REQUEST_URI'];
 }
Ejemplo n.º 9
0
 /**
  * Same as show error but return the content as a param
  *
  * @param array $p_aError
  * @return string The HTML contents
  */
 function getErrorForEmail($p_aError = "")
 {
     $oConfig = PPI_Helper::getConfig();
     $heading = "PHP Error";
     $baseUrl = $oConfig->system->base_url;
     require SYSTEMPATH . 'View/code_error.php';
     return $html;
 }
Ejemplo n.º 10
0
function roleIDToName($p_iID)
{
    if (!isset(PPI_Helper::getConfig()->system->roleMapping)) {
        throw new PPI_Exception('Trying to perform roleIDToName when no roleMapping information was found.');
    }
}
Ejemplo n.º 11
0
function writeErrorToLog($message)
{
    if (ini_get('log_errors') !== 'On') {
        return false;
    }
    $oConfig = PPI_Helper::getConfig();
    if (($sErrorLog = ini_get('error_log')) == 'syslog') {
        syslog(LOG_ALERT, "\n{$message}\n");
    } elseif ($sErrorLog !== '' && is_writable($sErrorLog)) {
        file_put_contents($sErrorLog, "\n{$message}\n", FILE_APPEND);
    }
}
Ejemplo n.º 12
0
 /**
  * Alias for $this->load() but forcing the renderer to smarty
  *
  * @param string $p_tplFile The template filename
  * @param array $p_tplParams Optional user defined params
  * @return void
  */
 function loadSmarty($p_tplFile, $p_tplParams = array())
 {
     $this->setupRenderer(new PPI_Helper_Template_Smarty(), $p_tplFile, $p_tplParams, PPI_Helper::getConfig());
 }
Ejemplo n.º 13
0
 /**
  * Convert the role ID by specifying the role name
  *
  * @static
  * @throws PPI_Exception
  * @param  string $p_sRoleName The role name
  * @return integer
  */
 static function getRoleIDFromName($p_sRoleName)
 {
     $oConfig = PPI_Helper::getConfig();
     $aRoles = $oConfig->system->roleMapping->toArray();
     if (array_key_exists($p_sRoleName, $aRoles)) {
         return $aRoles[$p_sRoleName];
     }
     throw new PPI_Exception('Unknown Role Type: ' . $p_sRoleName);
 }