示例#1
0
 private function randomQuotes($number)
 {
     require_once CRM_MODULE_INCLUDE_DIRECTORY . 'RandomStringGenerator.php';
     $random = new \creamy\RandomStringGenerator();
     $quotes = array();
     for ($i = 0; $i < $number; $i++) {
         $rnd = $random->getRandomInteger(1, 10);
         $author = $this->lh()->translationFor("author_" . $rnd);
         $quote = $this->lh()->translationFor("quote_" . $rnd);
         $quotes[] = array("quote" => $quote, "author" => $author, "author_number" => $rnd);
     }
     return $quotes;
 }
示例#2
0
 /**
  * Sends a activate user email with a security token to a user. This email will be sent to 
  * confirm the creation of a new user automatically. The user must click on the verification
  * link of this email up to 24 hours after the message is sent or it will not be valid.
  * Once the user clicks the link, their user account will be activated.
  */
 public function sendAccountActivationEmail($email)
 {
     // prepare values.
     $lh = \creamy\LanguageHandler::getInstance();
     $dateAsString = date('Y-m-d-H-i-s');
     $baseURL = \creamy\CRMUtils::creamyBaseURL();
     // generate a nonce to avoid replay attacks && the password reset code.
     $randomStringGenerator = new \creamy\RandomStringGenerator();
     $nonce = $randomStringGenerator->generate(40);
     // security code
     $securityToken = $this->db->generateEmailSecurityCode($email, $dateAsString, $nonce);
     // build the message.
     $title = $lh->translationFor("activate_account_title");
     $text = $lh->translationFor("activate_account_text");
     $linkTitle = $lh->translationFor("activate_account_title");
     $linkURL = "{$baseURL}/accountactivation.php?email=" . urlencode($email) . "&amp;code=" . urlencode($securityToken) . "&amp;date=" . urlencode($dateAsString) . "&amp;nonce=" . urlencode($nonce);
     return $this->sendCreamyEmailWithValues($title, $text, $linkURL, $linkTitle, $title, $email);
 }
示例#3
0
 /**
  * Adds a new customer type, creating the new customer tables and updating customer_types and statistics tables.
  */
 public function addNewCustomerType($description)
 {
     // we generate a random temporal name for the table.
     $rsg = new \creamy\RandomStringGenerator();
     $tempName = "temp" . $rsg->generate(20);
     $this->dbConnector->startTransaction();
     // first we need to insert the customer_type register, because we don't have a table_name yet.
     $data = array("table_name" => $tempName, "description" => $description);
     $id = $this->dbConnector->insert(CRM_CUSTOMER_TYPES_TABLE_NAME, $data);
     if ($id) {
         // if insertion was successful, use the generated auto_increment id to set the name of the table_name.
         $tableName = "clients_{$id}";
         $this->dbConnector->where("id", $id);
         $finalData = array("table_name" => $tableName);
         if ($this->dbConnector->update(CRM_CUSTOMER_TYPES_TABLE_NAME, $finalData)) {
             // success!
             // now we try to add the new customers table.
             if ($this->createNewCustomersTable($tableName)) {
                 // success!
                 // now try to add to statistics.
                 if ($this->dbConnector->addColumnToTable(CRM_STATISTICS_TABLE_NAME, $tableName, "INT(11) DEFAULT 0", "0")) {
                     // success!
                     $this->dbConnector->commit();
                     return true;
                 }
             }
         }
     }
     $this->dbConnector->rollback();
     return false;
 }
示例#4
0
 /**
  * Generates a new upload filepath. The base dir is the uploads directory, appending the
  * current year and month. Then a randomly generated filename will be used, with the
  * given extension. The method will create the intermediate directories if they don't exist.
  * @param String $extension		(optional) Extension to be added to the filename.
  * @param String $lockFile		If true, touches the file to lock it.
  */
 public static function generateUploadRelativePath($filename = null, $lockFile = false)
 {
     require_once 'RandomStringGenerator.php';
     $basedir = CRM_UPLOADS_DIRNAME . "/" . date('Y') . "/" . date('m') . "/";
     $baseDirInDisk = \creamy\CRMUtils::creamyBaseDirectoryPath() . $basedir;
     if (!is_dir($baseDirInDisk)) {
         mkdir($baseDirInDisk, 0775, true);
     }
     // create dir if it doesn't exists
     // check filename
     if (empty($filename)) {
         // return a random filename.
         $rnd = new \creamy\RandomStringGenerator();
         $filename = $rnd->generate(CRM_UPLOAD_FILENAME_LENGTH) . ".dat";
     }
     // check if file already exists.
     $i = 1;
     $filepath = $baseDirInDisk . $filename;
     while (file_exists($filepath)) {
         // add -$i to filename
         $components = pathinfo($filename, PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME);
         $filename = $components["filename"] . "-{$i}" . (isset($components["extension"]) ? $components["extension"] : "");
         $filepath = $baseDirInDisk . $filename;
         $i++;
     }
     // lock file (if $lockFile is set) so no other upload can access it.
     touch($filepath);
     // return relative url
     return $basedir . $filename;
 }
示例#5
0
 }
 if (isset($_POST["desiredLanguage"])) {
     $desiredLanguage = $_POST["desiredLanguage"];
 }
 // stablish connection with the database.
 $dbInstaller = new DBInstaller($dbhost, $dbname, $dbuser, $dbpass);
 if ($dbInstaller->getState() == CRM_INSTALL_STATE_SUCCESS) {
     // database access succeed. Try to set the basic tables.
     // update LanguageHandler locale
     error_log("Creamy install: Trying to set locale to {$locale}");
     $lh->setLanguageHandlerLocale($locale);
     // delete current database tables.
     $cleanResult = $dbInstaller->dropPreviousTables();
     if ($cleanResult == true) {
         // setup settings table.
         $randomStringGenerator = new \creamy\RandomStringGenerator();
         $crmSecurityCode = $randomStringGenerator->generate(40);
         $settingsResult = $dbInstaller->setupSettingTable($timezone, $desiredLanguage, $desiredLanguage);
         if ($settingsResult === true) {
             // generate a new config file for Creamy, incluying db information & timezone.
             $configContent = file_get_contents(CRM_INSTALL_SKEL_CONFIG_FILE);
             $customConfig = "\n// database configuration\ndefine('DB_USERNAME', '{$dbuser}');\ndefine('DB_PASSWORD', '{$dbpass}');\ndefine('DB_HOST', '{$dbhost}');\ndefine('DB_NAME', '{$dbname}');\ndefine('DB_PORT', '3306');\n\n// other configuration parameters\t\t\t\n" . CRM_PHP_END_TAG;
             $configContent = str_replace(CRM_PHP_END_TAG, $customConfig, $configContent);
             file_put_contents(CRM_PHP_CONFIG_FILE, $configContent);
             // set session credentials and continue installation.
             $_SESSION["dbhost"] = $dbhost;
             $_SESSION["dbname"] = $dbname;
             $_SESSION["dbuser"] = $dbuser;
             $_SESSION["dbpass"] = $dbpass;
             $error = "";
             $currentState = "step2";
示例#6
0
 /**
  * Processes a image uploaded to the system and generates a processed thumbnail image
  * suitable for the user avatar. The newly generated file is stored in the avatars images dir
  * and the relative URL to the file is returned. This relative path can be accessed through URL
  * by appending the CRMUtils class method creamyBaseURL, and through disk by appending the 
  * CRMUtils class method creamyBaseDirectoryPath.
  * @param String $imgSrc image 	file source (i.e: the uploaded $_FILES[parameter][tmp_name][i] value.
  * @param String $imageFileType image file type. If empty, it will be set to .jpg.
  * @return a relative path for the generated image. i.e: img/avatars/q4q893pv57hqc9m.jpg or NULL if an error happened.
  */
 public function generateAvatarFileAndReturnURL($imgSrc, $imageFileType = null)
 {
     // generate a random image name file (and make sure it's not in use.
     if (empty($imageFileType)) {
         $imageFileType = AVATAR_IMAGE_FILENAME_EXTENSION;
     }
     $rnd = new \creamy\RandomStringGenerator();
     $filename = $rnd->generate(AVATAR_IMAGE_FILENAME_LENGTH) . "." . $imageFileType;
     // get the filepath and check if the file already exists.
     $basedir = \creamy\CRMUtils::creamyBaseDirectoryPath();
     while (file_exists($basedir . AVATAR_IMAGE_FILEDIR . $filename)) {
         $filename = $rnd->generate(AVATAR_IMAGE_FILENAME_LENGTH) . "." . $imageFileType;
     }
     // touch file (to lock it from other processes trying to write that same filename).
     touch($basedir . AVATAR_IMAGE_FILEDIR . $filename);
     // process source image, generating a square image.
     $thumb = $this->generateThumbnailForImage($imgSrc, $imageFileType);
     // if successful, write the image to the generated path and return it.
     if ($thumb) {
         if (imagejpeg($thumb, $basedir . AVATAR_IMAGE_FILEDIR . $filename)) {
             imagedestroy($thumb);
             return AVATAR_IMAGE_FILEDIR . $filename;
         } else {
             imagedestroy($thumb);
             return null;
         }
     } else {
         return NULL;
     }
 }
示例#7
0
 protected function mergeHookResultsWithStrategy($results, $mergeStrategy)
 {
     switch ($mergeStrategy) {
         case CRM_MODULE_MERGING_STRATEGY_APPEND:
             $appended = "";
             foreach ($results as $result) {
                 if (is_string($result)) {
                     $appended .= $result;
                 } else {
                     $appended .= var_export($result, true);
                 }
             }
             return $appended;
             break;
         case CRM_MODULE_MERGING_STRATEGY_SUM:
             $sum = 0.0;
             foreach ($results as $result) {
                 $sum += floatval($result);
             }
             return $sum;
             break;
         case CRM_MODULE_MERGING_STRATEGY_JOIN:
             $joined = array();
             foreach ($results as $result) {
                 $joined = array_merge($joined, $result);
             }
             return $joined;
             break;
         case CRM_MODULE_MERGING_STRATEGY_AND:
             $andResult = true;
             foreach ($results as $result) {
                 $andResult = $andResult and (bool) $result;
             }
             return $andResult;
             break;
         case CRM_MODULE_MERGING_STRATEGY_OR:
             $oredResult = true;
             foreach ($results as $result) {
                 $oredResult = $oredResult or (bool) $result;
             }
             return $oredResult;
             break;
         case CRM_MODULE_MERGING_STRATEGY_FIRST:
             if (is_array($results) && count($results) > 0) {
                 return reset($results);
             } else {
                 return $results;
             }
             break;
         case CRM_MODULE_MERGING_STRATEGY_LAST:
             if (is_array($results) && count($results) > 0) {
                 return end($results);
             } else {
                 return $results;
             }
             break;
         case CRM_MODULE_MERGING_STRATEGY_RANDOM:
             if (is_array($results) && count($results) > 0) {
                 require_once 'RandomStringGenerator.php';
                 $rnd = new \creamy\RandomStringGenerator();
                 $nmb = $rnd->getRandomInteger(0, count($results) - 1);
                 return array_values($results)[$nmb];
             } else {
                 return $results;
             }
             break;
     }
 }