public static function upload($params)
 {
     if (!$_FILES) {
         throw new CRM_Extension_Exception('Sorry, the file you uploaded was too large or invalid. Code 1', 500);
     }
     if (empty($_FILES['file']['size'])) {
         throw new CRM_Extension_Exception('Sorry, the file you uploaded was too large or invalid. Code 2', 500);
     }
     $tempFile = $_FILES['file']['tmp_name'];
     $originalFilename = CRM_Simplemail_BAO_SimpleMailHelper::cleanFilename($_FILES['file']['name']);
     $fileName = CRM_Utils_File::makeFileName(CRM_Simplemail_BAO_SimpleMailHelper::cleanFilename($_FILES['file']['name']));
     $dirName = CRM_Simplemail_BAO_SimpleMailHelper::getUploadDirPath(static::DIRECTORY);
     // Create the upload directory, if it doesn't already exist
     CRM_Utils_File::createDir($dirName);
     $file = $dirName . $fileName;
     // Move the uploaded file to the upload directory
     if (move_uploaded_file($tempFile, $file)) {
         $url = CRM_Simplemail_BAO_SimpleMailHelper::getUploadUrl($fileName, static::DIRECTORY);
         $databaseId = static::saveToDatabase($params['simplemail_id'], $originalFilename, $url);
         $result['values'] = array(array('url' => $url, 'filename' => $originalFilename, 'databaseId' => $databaseId));
         return $result;
     } else {
         throw new CRM_Extension_Exception('Failed to move the uploaded file', 500);
     }
 }
Beispiel #2
0
 /**
  * @param string $repoUrl
  *   URL of the remote repository.
  * @param string $indexPath
  *   Relative path of the 'index' file within the repository.
  * @param string $cacheDir
  *   Local path in which to cache files.
  */
 public function __construct($repoUrl, $indexPath, $cacheDir)
 {
     $this->repoUrl = $repoUrl;
     $this->cacheDir = $cacheDir;
     $this->indexPath = empty($indexPath) ? self::SINGLE_FILE_PATH : $indexPath;
     if ($cacheDir && !file_exists($cacheDir) && is_dir(dirname($cacheDir)) && is_writable(dirname($cacheDir))) {
         CRM_Utils_File::createDir($cacheDir, FALSE);
     }
 }
Beispiel #3
0
 public function filePostProcess($data, $fileID, $entityTable, $entityID, $entitySubtype, $overwrite = true, $fileParams = null, $uploadName = 'uploadFile', $mimeType)
 {
     require_once 'CRM/Core/DAO/File.php';
     $config =& CRM_Core_Config::singleton();
     $path = explode('/', $data);
     $filename = $path[count($path) - 1];
     // rename this file to go into the secure directory
     if ($entitySubtype) {
         $directoryName = $config->customFileUploadDir . $entitySubtype . DIRECTORY_SEPARATOR . $entityID;
     } else {
         $directoryName = $config->customFileUploadDir;
     }
     require_once "CRM/Utils/File.php";
     CRM_Utils_File::createDir($directoryName);
     if (!rename($data, $directoryName . DIRECTORY_SEPARATOR . $filename)) {
         CRM_Core_Error::fatal(ts('Could not move custom file to custom upload directory'));
         break;
     }
     // to get id's
     if ($overwrite && $fileID) {
         list($sql, $params) = self::sql($entityTable, $entityID, $fileID);
     } else {
         list($sql, $params) = self::sql($entityTable, $entityID, 0);
     }
     $dao =& CRM_Core_DAO::executeQuery($sql, $params);
     $dao->fetch();
     if (!$mimeType) {
         CRM_Core_Error::fatal();
     }
     require_once "CRM/Core/DAO/File.php";
     $fileDAO =& new CRM_Core_DAO_File();
     if (isset($dao->cfID) && $dao->cfID) {
         $fileDAO->id = $dao->cfID;
         unlink($directoryName . DIRECTORY_SEPARATOR . $dao->uri);
     }
     if (!empty($fileParams)) {
         $fileDAO->copyValues($fileParams);
     }
     $fileDAO->uri = $filename;
     $fileDAO->mime_type = $mimeType;
     $fileDAO->file_type_id = $fileID;
     $fileDAO->upload_date = date('Ymdhis');
     $fileDAO->save();
     // need to add/update civicrm_entity_file
     require_once "CRM/Core/DAO/EntityFile.php";
     $entityFileDAO =& new CRM_Core_DAO_EntityFile();
     if (isset($dao->cefID) && $dao->cefID) {
         $entityFileDAO->id = $dao->cefID;
     }
     $entityFileDAO->entity_table = $entityTable;
     $entityFileDAO->entity_id = $entityID;
     $entityFileDAO->file_id = $fileDAO->id;
     $entityFileDAO->save();
 }
Beispiel #4
0
 private function initialize()
 {
     $config = CRM_Core_Config::singleton();
     if (isset($config->customTemplateDir) && $config->customTemplateDir) {
         $this->template_dir = array_merge(array($config->customTemplateDir), $config->templateDir);
     } else {
         $this->template_dir = $config->templateDir;
     }
     $this->compile_dir = CRM_Utils_File::addTrailingSlash(CRM_Utils_File::addTrailingSlash($config->templateCompileDir) . $this->getLocale());
     CRM_Utils_File::createDir($this->compile_dir);
     CRM_Utils_File::restrictAccess($this->compile_dir);
     // check and ensure it is writable
     // else we sometime suppress errors quietly and this results
     // in blank emails etc
     if (!is_writable($this->compile_dir)) {
         echo "CiviCRM does not have permission to write temp files in {$this->compile_dir}, Exiting";
         exit;
     }
     //Check for safe mode CRM-2207
     if (ini_get('safe_mode')) {
         $this->use_sub_dirs = FALSE;
     } else {
         $this->use_sub_dirs = TRUE;
     }
     $customPluginsDir = NULL;
     if (isset($config->customPHPPathDir)) {
         $customPluginsDir = $config->customPHPPathDir . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR;
         if (!file_exists($customPluginsDir)) {
             $customPluginsDir = NULL;
         }
     }
     $smartyDir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR;
     $pluginsDir = __DIR__ . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR;
     if ($customPluginsDir) {
         $this->plugins_dir = array($customPluginsDir, $smartyDir . 'plugins', $pluginsDir);
     } else {
         $this->plugins_dir = array($smartyDir . 'plugins', $pluginsDir);
     }
     // add the session and the config here
     $session = CRM_Core_Session::singleton();
     $this->assign_by_ref('config', $config);
     $this->assign_by_ref('session', $session);
     global $tsLocale;
     $this->assign('tsLocale', $tsLocale);
     // CRM-7163 hack: we don’t display langSwitch on upgrades anyway
     if (!CRM_Core_Config::isUpgradeMode()) {
         $this->assign('langSwitch', CRM_Core_I18n::languages(TRUE));
     }
     $this->register_function('crmURL', array('CRM_Utils_System', 'crmURL'));
     $this->load_filter('pre', 'resetExtScope');
     $this->assign('crmPermissions', new CRM_Core_Smarty_Permissions());
 }
Beispiel #5
0
 function createDir()
 {
     require_once 'CRM/Utils/File.php';
     // ensure that $this->_mailDir is a directory and is writable
     if (!is_dir($this->_mailDir) || !is_readable($this->_mailDir)) {
         echo "Could not read from {$this->_mailDir}\n";
         exit;
     }
     $config =& CRM_Core_Config::singleton();
     $dir = $config->uploadDir . DIRECTORY_SEPARATOR . 'mail';
     $this->_processedDir = $dir . DIRECTORY_SEPARATOR . 'processed';
     CRM_Utils_File::createDir($this->_processedDir);
     $this->_errorDir = $dir . DIRECTORY_SEPARATOR . 'error';
     CRM_Utils_File::createDir($this->_errorDir);
     // create a date string YYYYMMDD
     require_once 'CRM/Utils/Date.php';
     $date = CRM_Utils_Date::getToday(null, 'Ymd');
     $this->_processedDir = $this->_processedDir . DIRECTORY_SEPARATOR . $date;
     CRM_Utils_File::createDir($this->_processedDir);
     $this->_errorDir = $this->_errorDir . DIRECTORY_SEPARATOR . $date;
     CRM_Utils_File::createDir($this->_errorDir);
 }
Beispiel #6
0
 static function filePostProcess($data, $fileTypeID, $entityTable, $entityID, $entitySubtype, $overwrite = TRUE, $fileParams = NULL, $uploadName = 'uploadFile', $mimeType = null)
 {
     if (!$mimeType) {
         CRM_Core_Error::fatal(ts('Mime Type is now a required parameter'));
     }
     $config = CRM_Core_Config::singleton();
     $path = explode('/', $data);
     $filename = $path[count($path) - 1];
     // rename this file to go into the secure directory
     if ($entitySubtype) {
         $directoryName = $config->customFileUploadDir . $entitySubtype . DIRECTORY_SEPARATOR . $entityID;
     } else {
         $directoryName = $config->customFileUploadDir;
     }
     CRM_Utils_File::createDir($directoryName);
     if (!rename($data, $directoryName . DIRECTORY_SEPARATOR . $filename)) {
         CRM_Core_Error::fatal(ts('Could not move custom file to custom upload directory'));
         break;
     }
     // to get id's
     if ($overwrite && $fileTypeID) {
         list($sql, $params) = self::sql($entityTable, $entityID, $fileTypeID);
     } else {
         list($sql, $params) = self::sql($entityTable, $entityID, 0);
     }
     $dao = CRM_Core_DAO::executeQuery($sql, $params);
     $dao->fetch();
     $fileDAO = new CRM_Core_DAO_File();
     $op = 'create';
     if (isset($dao->cfID) && $dao->cfID) {
         $op = 'edit';
         $fileDAO->id = $dao->cfID;
         unlink($directoryName . DIRECTORY_SEPARATOR . $dao->uri);
     }
     if (!empty($fileParams)) {
         $fileDAO->copyValues($fileParams);
     }
     $fileDAO->uri = $filename;
     $fileDAO->mime_type = $mimeType;
     $fileDAO->file_type_id = $fileTypeID;
     $fileDAO->upload_date = date('Ymdhis');
     $fileDAO->save();
     // need to add/update civicrm_entity_file
     $entityFileDAO = new CRM_Core_DAO_EntityFile();
     if (isset($dao->cefID) && $dao->cefID) {
         $entityFileDAO->id = $dao->cefID;
     }
     $entityFileDAO->entity_table = $entityTable;
     $entityFileDAO->entity_id = $entityID;
     $entityFileDAO->file_id = $fileDAO->id;
     $entityFileDAO->save();
     //save static tags
     if (!empty($fileParams['tag'])) {
         CRM_Core_BAO_EntityTag::create($fileParams['tag'], 'civicrm_file', $entityFileDAO->id);
     }
     //save free tags
     if (isset($fileParams['attachment_taglist']) && !empty($fileParams['attachment_taglist'])) {
         CRM_Core_Form_Tag::postProcess($fileParams['attachment_taglist'], $entityFileDAO->id, 'civicrm_file', CRM_Core_DAO::$_nullObject);
     }
     // lets call the post hook here so attachments code can do the right stuff
     CRM_Utils_Hook::post($op, 'File', $fileDAO->id, $fileDAO);
 }
Beispiel #7
0
 /**
  * Deletes the web server writable directories.
  *
  * @param int $value
  *   1: clean templates_c, 2: clean upload, 3: clean both
  * @param bool $rmdir
  */
 public function cleanup($value, $rmdir = TRUE)
 {
     $value = (int) $value;
     if ($value & 1) {
         // clean templates_c
         CRM_Utils_File::cleanDir($this->templateCompileDir, $rmdir);
         CRM_Utils_File::createDir($this->templateCompileDir);
     }
     if ($value & 2) {
         // clean upload dir
         CRM_Utils_File::cleanDir($this->uploadDir);
         CRM_Utils_File::createDir($this->uploadDir);
     }
     // Whether we delete/create or simply preserve directories, we should
     // certainly make sure the restrictions are enforced.
     foreach (array($this->templateCompileDir, $this->uploadDir, $this->configAndLogDir, $this->customFileUploadDir) as $dir) {
         if ($dir && is_dir($dir)) {
             CRM_Utils_File::restrictAccess($dir);
         }
     }
 }
 /**
  * Set the default values.
  * in an empty db, also called when setting component using GUI
  *
  * @param array $defaults
  *   Associated array of form elements.
  * @param bool $formMode
  *   this variable is set true for GUI
  *   mode (eg: Global setting >> Components)
  *
  */
 public static function setValues(&$defaults, $formMode = FALSE)
 {
     $config = CRM_Core_Config::singleton();
     $baseURL = $config->userFrameworkBaseURL;
     // CRM-6216: Drupal’s $baseURL might have a trailing LANGUAGE_NEGOTIATION_PATH,
     // which needs to be stripped before we start basing ResourceURL on it
     if ($config->userSystem->is_drupal) {
         global $language;
         if (isset($language->prefix) and $language->prefix) {
             if (substr($baseURL, -(strlen($language->prefix) + 1)) == $language->prefix . '/') {
                 $baseURL = substr($baseURL, 0, -(strlen($language->prefix) + 1));
             }
         }
     }
     $baseCMSURL = CRM_Utils_System::baseCMSURL();
     if ($config->templateCompileDir) {
         $path = CRM_Utils_File::baseFilePath($config->templateCompileDir);
     }
     if (!isset($defaults['enableSSL'])) {
         $defaults['enableSSL'] = 0;
     }
     //set defaults if not set in db
     if (!isset($defaults['userFrameworkResourceURL'])) {
         if ($config->userFramework == 'Joomla') {
             $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/";
         } elseif ($config->userFramework == 'WordPress') {
             $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/";
         } else {
             // Drupal setting
             // check and see if we are installed in sites/all (for D5 and above)
             // we dont use checkURL since drupal generates an error page and throws
             // the system for a loop on lobo's macosx box
             // or in modules
             global $civicrm_root;
             $cmsPath = $config->userSystem->cmsRootPath();
             $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("{$cmsPath}/", '', str_replace('\\', '/', $civicrm_root));
             if (strpos($civicrm_root, DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules') === FALSE) {
                 $startPos = strpos($civicrm_root, DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR);
                 $endPos = strpos($civicrm_root, DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR);
                 if ($startPos && $endPos) {
                     // if component is in sites/SITENAME/modules
                     $siteName = substr($civicrm_root, $startPos + 7, $endPos - $startPos - 7);
                     $civicrmDirName = trim(basename($civicrm_root));
                     $defaults['userFrameworkResourceURL'] = $baseURL . "sites/{$siteName}/modules/{$civicrmDirName}/";
                     if (!isset($defaults['imageUploadURL'])) {
                         $defaults['imageUploadURL'] = $baseURL . "sites/{$siteName}/files/civicrm/persist/contribute/";
                     }
                 }
             }
         }
     }
     if (!isset($defaults['imageUploadURL'])) {
         if ($config->userFramework == 'Joomla') {
             // gross hack
             // we need to remove the administrator/ from the end
             $tempURL = str_replace("/administrator/", "/", $baseURL);
             $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
         } elseif ($config->userFramework == 'WordPress') {
             //for standalone no need of sites/defaults directory
             $defaults['imageUploadURL'] = $baseURL . "wp-content/plugins/files/civicrm/persist/contribute/";
         } else {
             $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
         }
     }
     if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) {
         $imgDir = $path . "persist/contribute/";
         CRM_Utils_File::createDir($imgDir);
         $defaults['imageUploadDir'] = $imgDir;
     }
     if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) {
         $uploadDir = $path . "upload/";
         CRM_Utils_File::createDir($uploadDir);
         CRM_Utils_File::restrictAccess($uploadDir);
         $defaults['uploadDir'] = $uploadDir;
     }
     if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) {
         $customDir = $path . "custom/";
         CRM_Utils_File::createDir($customDir);
         CRM_Utils_File::restrictAccess($customDir);
         $defaults['customFileUploadDir'] = $customDir;
     }
     // FIXME: hack to bypass the step for generating defaults for components,
     // while running upgrade, to avoid any serious non-recoverable error
     // which might hinder the upgrade process.
     $args = array();
     if (isset($_GET[$config->userFrameworkURLVar])) {
         $args = explode('/', $_GET[$config->userFrameworkURLVar]);
     }
     if (isset($defaults['enableComponents'])) {
         foreach ($defaults['enableComponents'] as $key => $name) {
             $comp = $config->componentRegistry->get($name);
             if ($comp) {
                 $co = $comp->getConfigObject();
                 $co->setDefaults($defaults);
             }
         }
     }
 }
Beispiel #9
0
 /**
  * delete the web server writable directories
  *
  * @param int $value 1 - clean templates_c, 2 - clean upload, 3 - clean both
  *
  * @access public
  * @return void
  */
 public function cleanup($value)
 {
     $value = (int) $value;
     if ($value & 1) {
         // clean templates_c
         CRM_Utils_File::cleanDir($this->templateCompileDir);
         CRM_Utils_File::createDir($this->templateCompileDir);
     }
     if ($value & 2) {
         // clean upload dir
         CRM_Utils_File::cleanDir($this->uploadDir);
         CRM_Utils_File::createDir($this->uploadDir);
     }
 }
Beispiel #10
0
 public function __get($k)
 {
     if (!isset($this->map[$k])) {
         throw new \CRM_Core_Exception("Cannot read unrecognized property CRM_Core_Config::\${$k}.");
     }
     if (isset($this->cache[$k])) {
         return $this->cache[$k];
     }
     $type = $this->map[$k][0];
     $name = isset($this->map[$k][1]) ? $this->map[$k][1] : $k;
     switch ($type) {
         case 'setting':
             return $this->getSettings()->get($name);
         case 'setting-path':
             // Array(0 => $type, 1 => $setting, 2 => $actions).
             $value = $this->getSettings()->get($name);
             $value = Civi::paths()->getPath($value);
             if ($value) {
                 $value = CRM_Utils_File::addTrailingSlash($value);
                 if (isset($this->map[$k][2]) && in_array('mkdir', $this->map[$k][2])) {
                     CRM_Utils_File::createDir($value);
                 }
                 if (isset($this->map[$k][2]) && in_array('restrict', $this->map[$k][2])) {
                     CRM_Utils_File::restrictAccess($value);
                 }
             }
             $this->cache[$k] = $value;
             return $value;
         case 'setting-url-abs':
             $value = $this->getSettings()->get($name);
             $this->cache[$k] = Civi::paths()->getUrl($value, 'absolute');
             return $this->cache[$k];
         case 'setting-url-rel':
             $value = $this->getSettings()->get($name);
             $this->cache[$k] = Civi::paths()->getUrl($value, 'relative');
             return $this->cache[$k];
         case 'runtime':
             return \Civi\Core\Container::getBootService('runtime')->{$name};
         case 'boot-svc':
             $this->cache[$k] = \Civi\Core\Container::getBootService($name);
             return $this->cache[$k];
         case 'local':
             $this->initLocals();
             return $this->locals[$name];
         case 'user-system':
             $userSystem = \Civi\Core\Container::getBootService('userSystem');
             $this->cache[$k] = call_user_func(array($userSystem, $name));
             return $this->cache[$k];
         case 'service':
             return \Civi::service($name);
         case 'callback':
             // Array(0 => $type, 1 => $obj, 2 => $getter, 3 => $setter, 4 => $unsetter).
             if (!isset($this->map[$k][1], $this->map[$k][2])) {
                 throw new \CRM_Core_Exception("Cannot find getter for property CRM_Core_Config::\${$k}");
             }
             return \Civi\Core\Resolver::singleton()->call(array($this->map[$k][1], $this->map[$k][2]), array($k));
         default:
             throw new \CRM_Core_Exception("Cannot read property CRM_Core_Config::\${$k} ({$type})");
     }
 }
 function logger(&$to, &$headers, &$message)
 {
     if (is_array($to)) {
         $toString = implode(', ', $to);
         $fileName = $to[0];
     } else {
         $toString = $fileName = $to;
     }
     $content = "To: " . $toString . "\n";
     foreach ($headers as $key => $val) {
         $content .= "{$key}: {$val}\n";
     }
     $content .= "\n" . $message . "\n";
     if (is_numeric(CIVICRM_MAIL_LOG)) {
         $config = CRM_Core_Config::singleton();
         // create the directory if not there
         $dirName = $config->configAndLogDir . 'mail' . DIRECTORY_SEPARATOR;
         CRM_Utils_File::createDir($dirName);
         $fileName = md5(uniqid(CRM_Utils_String::munge($fileName))) . '.txt';
         file_put_contents($dirName . $fileName, $content);
     } else {
         file_put_contents(CIVICRM_MAIL_LOG, $content, FILE_APPEND);
     }
 }
Beispiel #12
0
 /**
  * create a directory given a path name, creates parent directories
  * if needed
  * 
  * @param string $path  the path name
  * @param boolean $abort should we abort or just return an invalid code
  *
  * @return void
  * @access public
  * @static
  */
 function createDir($path, $abort = true)
 {
     if (is_dir($path) || empty($path)) {
         return;
     }
     CRM_Utils_File::createDir(dirname($path), $abort);
     if (@mkdir($path, 0777) == false) {
         if ($abort) {
             $docLink = CRM_Utils_System::docURL2('Moving an Existing Installation to a New Server or Location', false, 'Moving an Existing Installation to a New Server or Location');
             echo "Error: Could not create directory: {$path}.<p>If you have moved an existing CiviCRM installation from one location or server to another there are several steps you will need to follow. They are detailed on this CiviCRM wiki page - {$docLink}. A fix for the specific problem that caused this error message to be displayed is to set the value of the config_backend column in the civicrm_domain table to NULL. However we strongly recommend that you review and follow all the steps in that document.</p>";
             exit;
         } else {
             return false;
         }
     }
     return true;
 }
 /**
  * delete the web server writable directories
  *
  * @param int $value 1 - clean templates_c, 2 - clean upload, 3 - clean both
  *
  * @access public
  *
  * @return void
  */
 public function cleanup($value, $rmdir = TRUE)
 {
     $value = (int) $value;
     if ($value & 1) {
         // clean templates_c
         CRM_Utils_File::cleanDir($this->templateCompileDir, $rmdir);
         CRM_Utils_File::createDir($this->templateCompileDir);
     }
     if ($value & 2) {
         // clean upload dir
         CRM_Utils_File::cleanDir($this->uploadDir);
         CRM_Utils_File::createDir($this->uploadDir);
         CRM_Utils_File::restrictAccess($this->uploadDir);
     }
 }
Beispiel #14
0
 /**
  * The constructor. Basically redefines the class variables if
  * it finds a constant definition for that class variable
  *
  * @return object
  * @access private
  */
 function CRM_Core_Config()
 {
     require_once 'CRM/Core/Session.php';
     $session =& CRM_Core_Session::singleton();
     if (defined('CIVICRM_DOMAIN_ID')) {
         $GLOBALS['_CRM_CORE_CONFIG']['_domainID'] = CIVICRM_DOMAIN_ID;
     } else {
         $GLOBALS['_CRM_CORE_CONFIG']['_domainID'] = 1;
     }
     $session->set('domainID', $GLOBALS['_CRM_CORE_CONFIG']['_domainID']);
     // we figure this out early, since some config parameters are loaded
     // based on what components are enabled
     if (defined('ENABLE_COMPONENTS')) {
         $this->enableComponents = explode(',', ENABLE_COMPONENTS);
         for ($i = 0; $i < count($this->enableComponents); $i++) {
             $this->enableComponents[$i] = trim($this->enableComponents[$i]);
         }
     }
     if (defined('CIVICRM_DSN')) {
         $this->dsn = CIVICRM_DSN;
     }
     if (defined('UF_DSN')) {
         $this->ufDSN = UF_DSN;
     }
     if (defined('UF_USERTABLENAME')) {
         $this->ufUserTableName = UF_USERTABLENAME;
     }
     if (defined('CIVICRM_DEBUG')) {
         $this->debug = CIVICRM_DEBUG;
     }
     if (defined('CIVICRM_DAO_DEBUG')) {
         $this->daoDebug = CIVICRM_DAO_DEBUG;
     }
     if (defined('CIVICRM_DAO_FACTORY_CLASS')) {
         $this->DAOFactoryClass = CIVICRM_DAO_FACTORY_CLASS;
     }
     if (defined('CIVICRM_SMARTYDIR')) {
         $this->smartyDir = CIVICRM_SMARTYDIR;
     }
     if (defined('CIVICRM_PLUGINSDIR')) {
         $this->pluginsDir = CIVICRM_PLUGINSDIR;
     }
     if (defined('CIVICRM_TEMPLATEDIR')) {
         $this->templateDir = CIVICRM_TEMPLATEDIR;
     }
     if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
         $this->templateCompileDir = CIVICRM_TEMPLATE_COMPILEDIR;
         // make sure this directory exists
         CRM_Utils_File::createDir($this->templateCompileDir);
     }
     if (defined('CIVICRM_RESOURCEBASE')) {
         $this->resourceBase = CRM_Core_Config::addTrailingSlash(CIVICRM_RESOURCEBASE, '/');
     }
     if (defined('CIVICRM_UPLOADDIR')) {
         $this->uploadDir = CRM_Core_Config::addTrailingSlash(CIVICRM_UPLOADDIR);
         CRM_Utils_File::createDir($this->uploadDir);
     }
     if (defined('CIVICRM_IMAGE_UPLOADDIR')) {
         $this->imageUploadDir = CRM_Core_Config::addTrailingSlash(CIVICRM_IMAGE_UPLOADDIR);
         CRM_Utils_File::createDir($this->imageUploadDir);
     }
     if (defined('CIVICRM_IMAGE_UPLOADURL')) {
         $this->imageUploadURL = CRM_Core_Config::addTrailingSlash(CIVICRM_IMAGE_UPLOADURL, '/');
     }
     if (defined('CIVICRM_CLEANURL')) {
         $this->cleanURL = CIVICRM_CLEANURL;
     }
     if (defined('CIVICRM_COUNTRY_LIMIT')) {
         $isoCodes = preg_split('/[^a-zA-Z]/', CIVICRM_COUNTRY_LIMIT);
         $this->countryLimit = array_filter($isoCodes);
     }
     if (defined('CIVICRM_PROVINCE_LIMIT')) {
         $isoCodes = preg_split('/[^a-zA-Z]/', CIVICRM_PROVINCE_LIMIT);
         $provinceLimitList = array_filter($isoCodes);
         if (!empty($provinceLimitList)) {
             $this->provinceLimit = array_filter($isoCodes);
         }
     }
     // Note: we can't change the ISO code to country_id
     // here, as we can't access the database yet...
     if (defined('CIVICRM_DEFAULT_CONTACT_COUNTRY')) {
         $this->defaultContactCountry = CIVICRM_DEFAULT_CONTACT_COUNTRY;
     }
     if (defined('CIVICONTRIBUTE_DEFAULT_CURRENCY') and CRM_Utils_Rule::currencyCode(CIVICONTRIBUTE_DEFAULT_CURRENCY)) {
         $this->defaultCurrency = CIVICONTRIBUTE_DEFAULT_CURRENCY;
     }
     if (defined('CIVICRM_LC_MESSAGES')) {
         $this->lcMessages = CIVICRM_LC_MESSAGES;
     }
     if (defined('CIVICRM_ADDRESS_FORMAT')) {
         // trim the format and unify line endings to LF
         $format = trim(CIVICRM_ADDRESS_FORMAT);
         $format = str_replace(array("\r\n", "\r"), "\n", $format);
         // get the field sequence from the format
         $newSequence = array();
         foreach ($this->addressSequence as $field) {
             if (substr_count($format, $field)) {
                 $newSequence[strpos($format, $field)] = $field;
             }
         }
         ksort($newSequence);
         // add the addressSequence fields that are missing in the addressFormat
         // to the end of the list, so that (for example) if state_province is not
         // specified in the addressFormat it's still in the address-editing form
         $newSequence = array_merge($newSequence, $this->addressSequence);
         $newSequence = array_unique($newSequence);
         $this->addressSequence = $newSequence;
         $this->addressFormat = $format;
     }
     if (defined('CIVICRM_DATEFORMAT_DATETIME')) {
         $this->dateformatDatetime = CIVICRM_DATEFORMAT_DATETIME;
     }
     if (defined('CIVICRM_DATEFORMAT_FULL')) {
         $this->dateformatFull = CIVICRM_DATEFORMAT_FULL;
     }
     if (defined('CIVICRM_DATEFORMAT_PARTIAL')) {
         $this->dateformatPartial = CIVICRM_DATEFORMAT_PARTIAL;
     }
     if (defined('CIVICRM_DATEFORMAT_YEAR')) {
         $this->dateformatYear = CIVICRM_DATEFORMAT_YEAR;
     }
     if (defined('CIVICRM_DATEFORMAT_QF_DATE')) {
         $this->dateformatQfDate = CIVICRM_DATEFORMAT_QF_DATE;
     }
     if (defined('CIVICRM_DATEFORMAT_QF_DATETIME')) {
         $this->dateformatQfDatetime = CIVICRM_DATEFORMAT_QF_DATETIME;
     }
     if (defined('CIVICRM_MONEYFORMAT')) {
         $this->moneyformat = CIVICRM_MONEYFORMAT;
     }
     if (defined('CIVICRM_LC_MONETARY')) {
         $this->lcMonetary = CIVICRM_LC_MONETARY;
         setlocale(LC_MONETARY, $this->lcMonetary . '.UTF-8', $this->lcMonetary, 'C');
     }
     if (defined('CIVICRM_GETTEXT_CODESET')) {
         $this->gettextCodeset = CIVICRM_GETTEXT_CODESET;
     }
     if (defined('CIVICRM_GETTEXT_DOMAIN')) {
         $this->gettextDomain = CIVICRM_GETTEXT_DOMAIN;
     }
     if (defined('CIVICRM_GETTEXT_RESOURCEDIR')) {
         $this->gettextResourceDir = CRM_Core_Config::addTrailingSlash(CIVICRM_GETTEXT_RESOURCEDIR);
     }
     if (defined('CIVICRM_SMTP_SERVER')) {
         $this->smtpServer = CIVICRM_SMTP_SERVER;
     }
     if (defined('CIVICRM_SMTP_PORT')) {
         $this->smtpPort = CIVICRM_SMTP_PORT;
     }
     if (defined('CIVICRM_SMTP_AUTH')) {
         if (CIVICRM_SMTP_AUTH === true) {
             $this->smtpAuth = true;
         }
         // else it stays false
     }
     if (defined('CIVICRM_SMTP_USERNAME')) {
         $this->smtpUsername = CIVICRM_SMTP_USERNAME;
     }
     if (defined('CIVICRM_SMTP_PASSWORD')) {
         $this->smtpPassword = CIVICRM_SMTP_PASSWORD;
     }
     if (defined('CIVICRM_UF')) {
         $this->userFramework = CIVICRM_UF;
         $this->userFrameworkClass = 'CRM_Utils_System_' . $this->userFramework;
         $this->userHookClass = 'CRM_Utils_Hook_' . $this->userFramework;
         $this->userPermissionClass = 'CRM_Core_Permission_' . $this->userFramework;
     }
     if (defined('CIVICRM_UF_VERSION')) {
         $this->userFrameworkVersion = (double) CIVICRM_UF_VERSION;
     }
     if (defined('CIVICRM_UF_URLVAR')) {
         $this->userFrameworkURLVar = CIVICRM_UF_URLVAR;
     }
     if (defined('CIVICRM_UF_DSN')) {
         $this->userFrameworkDSN = CIVICRM_UF_DSN;
     }
     if (defined('CIVICRM_UF_USERSTABLENAME')) {
         $this->userFrameworkUsersTableName = CIVICRM_UF_USERSTABLENAME;
     }
     if (defined('CIVICRM_UF_BASEURL')) {
         $this->userFrameworkBaseURL = CRM_Core_Config::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
     }
     if (defined('CIVICRM_UF_RESOURCEURL')) {
         $this->userFrameworkResourceURL = CRM_Core_Config::addTrailingSlash(CIVICRM_UF_RESOURCEURL, '/');
     }
     if (defined('CIVICRM_UF_FRONTEND')) {
         $this->userFrameworkFrontend = CIVICRM_UF_FRONTEND;
     }
     if (defined('CIVICRM_MYSQL_VERSION')) {
         $this->mysqlVersion = CIVICRM_MYSQL_VERSION;
     }
     if (defined('CIVICRM_MYSQL_PATH')) {
         $this->mysqlPath = CIVICRM_MYSQL_PATH;
     }
     $size = trim(ini_get('upload_max_filesize'));
     if ($size) {
         $last = strtolower($size[strlen($size) - 1]);
         switch ($last) {
             // The 'G' modifier is available since PHP 5.1.0
             case 'g':
                 $size *= 1024;
             case 'm':
                 $size *= 1024;
             case 'k':
                 $size *= 1024;
         }
         $this->maxImportFileSize = $size;
     }
     if (defined('CIVICRM_MAP_PROVIDER')) {
         $this->mapProvider = CIVICRM_MAP_PROVIDER;
     }
     if (defined('CIVICRM_MAP_API_KEY')) {
         $this->mapAPIKey = CIVICRM_MAP_API_KEY;
     }
     if (defined('CIVICRM_GEOCODE_METHOD')) {
         if (CIVICRM_GEOCODE_METHOD == 'CRM_Utils_Geocode_ZipTable' || CIVICRM_GEOCODE_METHOD == 'CRM_Utils_Geocode_RPC' || CIVICRM_GEOCODE_METHOD == 'CRM_Utils_Geocode_Yahoo') {
             $this->geocodeMethod = CIVICRM_GEOCODE_METHOD;
         }
     }
     if (defined('CIVICRM_VERSION_CHECK') and CIVICRM_VERSION_CHECK) {
         $this->versionCheck = true;
     }
     if (defined('CIVICRM_MAILER_SPOOL_PERIOD')) {
         $this->mailerPeriod = CIVICRM_MAILER_SPOOL_PERIOD;
     }
     if (defined('CIVICRM_VERP_SEPARATOR')) {
         $this->verpSeparator = CIVICRM_VERP_SEPARATOR;
     }
     if (defined('CIVICRM_ENABLE_SSL')) {
         $this->enableSSL = CIVICRM_ENABLE_SSL;
     }
     if (in_array('CiviContribute', $this->enableComponents)) {
         require_once 'CRM/Contribute/Config.php';
         CRM_Contribute_Config::add($this);
     }
     if (in_array('CiviSMS', $this->enableComponents)) {
         require_once 'CRM/SMS/Config.php';
         CRM_SMS_Config::add($this);
     }
     // initialize the framework
     $this->initialize();
 }
function civicrm_api3_civi_outlook_processattachments($params)
{
    //Get mime type of the attachment
    $mimeType = CRM_Utils_Type::escape($_REQUEST['mimeType'], 'String');
    $params['mime_type'] = $mimeType;
    $config = CRM_Core_Config::singleton();
    $directoryName = $config->customFileUploadDir;
    CRM_Utils_File::createDir($directoryName);
    //Process the below only if there is any attachment found
    if (CRM_Utils_Array::value("name", $_FILES['file'])) {
        $tmp_name = $_FILES['file']['tmp_name'];
        $name = str_replace(' ', '_', $_FILES['file']['name']);
        //Replace any spaces in name with underscore
        $fileExtension = new SplFileInfo($name);
        if ($fileExtension->getExtension()) {
            $explodeName = explode("." . $fileExtension->getExtension(), $name);
            $name = $explodeName[0] . "_" . md5($name) . "." . $fileExtension->getExtension();
        }
        $_FILES['file']['uri'] = $name;
        move_uploaded_file($tmp_name, "{$directoryName}{$name}");
        foreach ($_FILES['file'] as $key => $value) {
            $params[$key] = $value;
        }
        $result = civicrm_api3('File', 'create', $params);
        if (CRM_Utils_Array::value('id', $result)) {
            if (CRM_Utils_Array::value('activityID', $params)) {
                $lastActivityID = $params['activityID'];
            }
            $entityFileDAO = new CRM_Core_DAO_EntityFile();
            $entityFileDAO->entity_table = 'civicrm_activity';
            $entityFileDAO->entity_id = $lastActivityID;
            $entityFileDAO->file_id = $result['id'];
            $entityFileDAO->save();
        }
    }
    return civicrm_api3_create_success($entityFileDAO, $params);
}
 /**
  * @param $params
  *
  * @return array
  * @throws CRM_Extension_Exception
  */
 public static function uploadImage($params)
 {
     $tempFile = $_FILES['file']['tmp_name'];
     $fileName = CRM_Utils_File::makeFileName($_FILES['file']['name']);
     $dirName = static::getImageDirPath($params['field']);
     // Create the upload directory, if it doesn't already exist
     CRM_Utils_File::createDir($dirName);
     $file = $dirName . $fileName;
     // Move the uploaded file to the upload directory
     if (move_uploaded_file($tempFile, $file)) {
         $imageUrl = static::getImageUrl($fileName, $params['field']);
         $result['values'] = array(array('imageUrl' => $imageUrl, 'imageFileName' => $fileName));
         return $result;
     } else {
         throw new CRM_Extension_Exception('Failed to move the uploaded file', 500);
     }
 }
Beispiel #17
0
 /**
  * create a directory given a path name, creates parent directories
  * if needed
  * 
  * @param string $path  the path name
  *
  * @return void
  * @access public
  * @static
  */
 function createDir($path)
 {
     if (is_dir($path)) {
         return;
     }
     CRM_Utils_File::createDir(dirname($path));
     mkdir($path, 0777);
 }
 /**
  * Constructor - we're not initializing information here
  * since we don't want any database hits upon object
  * initialization.
  *
  * @access public
  *
  * @return void
  */
 public function __construct()
 {
     $config = CRM_Core_Config::singleton();
     if (isset($config->extensionsDir)) {
         $this->_extDir = $config->extensionsDir;
     }
     if (!empty($this->_extDir)) {
         $this->enabled = TRUE;
         $tmp = $this->_extDir . DIRECTORY_SEPARATOR . 'tmp';
         $cache = $this->_extDir . DIRECTORY_SEPARATOR . 'cache';
         if (is_writable($this->_extDir)) {
             if (!file_exists($tmp)) {
                 CRM_Utils_File::createDir($tmp, FALSE);
             }
             if (!file_exists($cache)) {
                 CRM_Utils_File::createDir($cache, FALSE);
             }
         } else {
             if (CRM_Core_Permission::check('administer CiviCRM') && $this->isDownloadEnabled()) {
                 $civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'));
                 $url = CRM_Utils_System::url('civicrm/admin/setting/path', "reset=1&civicrmDestination={$civicrmDestination}");
                 CRM_Core_Session::setStatus(ts('Your extensions directory: %1 is not web server writable. Please go to the <a href="%2">path setting page</a> and correct it.<br/>', array(1 => $this->_extDir, 2 => $url)));
             }
             $this->_extDir = NULL;
         }
         if (!class_exists('ZipArchive') && CRM_Core_Permission::check('administer CiviCRM') && $this->isDownloadEnabled()) {
             // everyone else is dumping messages wily-nily, why can't I?
             CRM_Core_Session::setStatus(ts('You will not be able to install extensions at this time because your installation of PHP does not support ZIP archives. Please ask your system administrator to install the standard PHP-ZIP extension.'));
         }
         if (empty($config->extensionsURL) && CRM_Core_Permission::check('administer CiviCRM')) {
             $civicrmDestination = urlencode(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1'));
             $url = CRM_Utils_System::url('civicrm/admin/setting/url', "reset=1&civicrmDestination={$civicrmDestination}");
             CRM_Core_Session::setStatus(ts('Your Extensions Directory (%1) does not have a matching Extensions Resource URL. Please go to the <a href="%2">URL setting page</a> and correct it.<br/>', array(1 => $this->_extDir, 2 => $url)));
         }
     }
 }
Beispiel #19
0
 /**
  * Function to set the default values
  *
  * @param array   $defaults  associated array of form elements
  * @param boolena $formMode  this funtion is called to set default
  *                           values in an empty db, also called when setting component using GUI
  *                           this variable is set true for GUI
  *                           mode (eg: Global setting >> Components)    
  *
  * @access public
  */
 public function setValues(&$defaults, $formMode = false)
 {
     $config =& CRM_Core_Config::singleton();
     $baseURL = $config->userFrameworkBaseURL;
     if ($config->templateCompileDir) {
         $path = dirname($config->templateCompileDir);
         //this fix is to avoid creation of upload dirs inside templates_c directory
         $checkPath = explode(DIRECTORY_SEPARATOR, $path);
         $cnt = count($checkPath) - 1;
         if ($checkPath[$cnt] == 'templates_c') {
             unset($checkPath[$cnt]);
             $path = implode(DIRECTORY_SEPARATOR, $checkPath);
         }
         $path = CRM_Utils_File::addTrailingSlash($path);
     }
     //set defaults if not set in db
     if (!isset($defaults['userFrameworkResourceURL'])) {
         $testIMG = "i/tracker.gif";
         if ($config->userFramework == 'Joomla') {
             if (CRM_Utils_System::checkURL("{$baseURL}components/com_civicrm/civicrm/{$testIMG}")) {
                 $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/";
             }
         } else {
             if ($config->userFramework == 'Standalone') {
                 // potentially sane default for standalone;
                 // could probably be smarter about this, but this
                 // should work in many cases
                 $defaults['userFrameworkResourceURL'] = str_replace('standalone/', '', $baseURL);
             } else {
                 // Drupal setting
                 // check and see if we are installed in sites/all (for D5 and above)
                 // we dont use checkURL since drupal generates an error page and throws
                 // the system for a loop on lobo's macosx box
                 // or in modules
                 global $civicrm_root;
                 $civicrmDirName = trim(basename($civicrm_root));
                 $defaults['userFrameworkResourceURL'] = $baseURL . "sites/all/modules/{$civicrmDirName}/";
                 if (strpos($civicrm_root, DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules') === false) {
                     $startPos = strpos($civicrm_root, DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR);
                     $endPos = strpos($civicrm_root, DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR);
                     if ($startPos && $endPos) {
                         // if component is in sites/SITENAME/modules
                         $siteName = substr($civicrm_root, $startPos + 7, $endPos - $startPos - 7);
                         $defaults['userFrameworkResourceURL'] = $baseURL . "sites/{$siteName}/modules/{$civicrmDirName}/";
                         if (!isset($defaults['imageUploadURL'])) {
                             $defaults['imageUploadURL'] = $baseURL . "sites/{$siteName}/files/civicrm/persist/contribute/";
                         }
                     }
                 }
             }
         }
     }
     if (!isset($defaults['imageUploadURL'])) {
         if ($config->userFramework == 'Joomla') {
             // gross hack
             // we need to remove the administrator/ from the end
             $tempURL = str_replace("/administrator/", "/", $baseURL);
             $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
         } else {
             if ($config->userFramework == 'Standalone') {
                 //for standalone no need of sites/defaults directory
                 $defaults['imageUploadURL'] = $baseURL . "files/civicrm/persist/contribute/";
             } else {
                 $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
             }
         }
     }
     if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) {
         $imgDir = $path . "persist/contribute/";
         CRM_Utils_File::createDir($imgDir);
         $defaults['imageUploadDir'] = $imgDir;
     }
     if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) {
         $uploadDir = $path . "upload/";
         CRM_Utils_File::createDir($uploadDir);
         $defaults['uploadDir'] = $uploadDir;
     }
     if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) {
         $customDir = $path . "custom/";
         CRM_Utils_File::createDir($customDir);
         $defaults['customFileUploadDir'] = $customDir;
     }
     /* FIXME: hack to bypass the step for generating defaults for components, 
        while running upgrade, to avoid any serious non-recoverable error 
        which might hinder the upgrade process. */
     $args = array();
     if (isset($_GET[$config->userFrameworkURLVar])) {
         $args = explode('/', $_GET[$config->userFrameworkURLVar]);
     }
     foreach ($defaults['enableComponents'] as $key => $name) {
         $comp = $config->componentRegistry->get($name);
         if ($comp) {
             $co = $comp->getConfigObject();
             $co->setDefaults($defaults);
         }
     }
 }
Beispiel #20
0
 /**
  * @param bool $loadFromDB
  */
 public function initialize($loadFromDB = TRUE)
 {
     if (!defined('CIVICRM_DSN') && $loadFromDB) {
         $this->fatal('You need to define CIVICRM_DSN in civicrm.settings.php');
     }
     $this->dsn = defined('CIVICRM_DSN') ? CIVICRM_DSN : NULL;
     if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') && $loadFromDB) {
         $this->fatal('You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php');
     }
     if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
         $this->configAndLogDir = CRM_Utils_File::baseFilePath() . 'ConfigAndLog' . DIRECTORY_SEPARATOR;
         CRM_Utils_File::createDir($this->configAndLogDir);
         CRM_Utils_File::restrictAccess($this->configAndLogDir);
         $this->templateCompileDir = defined('CIVICRM_TEMPLATE_COMPILEDIR') ? CRM_Utils_File::addTrailingSlash(CIVICRM_TEMPLATE_COMPILEDIR) : NULL;
         CRM_Utils_File::createDir($this->templateCompileDir);
         CRM_Utils_File::restrictAccess($this->templateCompileDir);
     }
     if (!defined('CIVICRM_UF')) {
         $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
     }
     $this->userFramework = CIVICRM_UF;
     $this->userFrameworkClass = 'CRM_Utils_System_' . CIVICRM_UF;
     $this->userHookClass = 'CRM_Utils_Hook_' . CIVICRM_UF;
     if (CIVICRM_UF == 'Joomla') {
         $this->userFrameworkURLVar = 'task';
     }
     if (defined('CIVICRM_UF_DSN')) {
         $this->userFrameworkDSN = CIVICRM_UF_DSN;
     }
     // this is dynamically figured out in the civicrm.settings.php file
     if (defined('CIVICRM_CLEANURL')) {
         $this->cleanURL = CIVICRM_CLEANURL;
     } else {
         $this->cleanURL = 0;
     }
     $this->templateDir = array(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR);
     $this->initialized = 1;
 }
Beispiel #21
0
 /**
  * Build The Bar Gharph image with given params 
  * and store in upload/pChart directory.
  *
  * @param  array  $params    an assoc array of name/value pairs          
  * @return array  $filesPath created image files Path.
  *
  * @static
  */
 static function barGraph($params, $divisionWidth = 44)
 {
     if (empty($params)) {
         return;
     }
     //get the required directory path.
     $config =& CRM_Core_Config::singleton();
     //get the default currency.
     $currency = $config->defaultCurrency;
     $pChartPath = str_replace('templates', 'packages', $config->templateDir);
     $pChartPath .= 'pChart/Fonts/';
     $uploadDirURL = str_replace('persist/contribute/', 'upload/pChart/', $config->imageUploadURL);
     $uploadDirPath = $config->uploadDir . 'pChart/';
     //create pchart directory, if exist clean and then create again.
     if (is_dir($uploadDirPath)) {
         CRM_Utils_File::cleanDir($uploadDirPath);
         CRM_Utils_File::createDir($uploadDirPath);
     } else {
         CRM_Utils_File::createDir($uploadDirPath);
     }
     require_once 'packages/pChart/pData.class.php';
     require_once 'packages/pChart/pChart.class.php';
     $chartCount = 0;
     $filesValues = array();
     foreach ($params as $chartIndex => $chartValues) {
         $chartCount++;
         $shades = 0;
         $names = $values = array();
         foreach ($chartValues['values'] as $indexName => $indexValue) {
             $names[] = $indexName;
             $values[] = $indexValue;
             $shades++;
         }
         $legend = CRM_Utils_Array::value('legend', $chartValues);
         $xname = CRM_Utils_Array::value('xname', $chartValues);
         $yname = CRM_Utils_Array::value('yname', $chartValues);
         //calculate max scale for graph.
         $maxScale = ceil(max($values) * 1.1);
         $fontSize = 8;
         $angleOfIncline = 45;
         $monetaryformatting = true;
         require_once 'CRM/Utils/Money.php';
         $formatedMoney = CRM_Utils_Money::format(max($values));
         $positions = imageftbbox($fontSize, 0, $pChartPath . "tahoma.ttf", $formatedMoney);
         $scaleTextWidth = $positions[2] - $positions[0];
         //need to increase Ysize if we incline money value.
         $increaseYBy = 0;
         $inclinePositions = imageftbbox($fontSize, $angleOfIncline, $pChartPath . "tahoma.ttf", $formatedMoney);
         $inclineTextWidth = $inclinePositions[2] - $inclinePositions[0];
         if ($inclineTextWidth > $divisionWidth) {
             $increaseYBy = $inclineTextWidth / 2;
         }
         //Initialise the co-ordinates.
         $xComponent = 20;
         $yComponent = 35;
         $ySize = 300;
         //calculate coords.
         $x1 = $xComponent + $scaleTextWidth;
         $y1 = $yComponent + $increaseYBy;
         $ySize += $increaseYBy;
         $y2 = $ySize - $yComponent;
         //calculate x axis size as per number of months.
         $x2 = $xComponent + $divisionWidth + $scaleTextWidth + (count($chartValues['values']) - 1) * $divisionWidth;
         $xSize = $x2 + $xComponent;
         $dataSet = new pData();
         $dataSet->AddPoint($values, "Serie1");
         $dataSet->AddPoint($names, "Serie2");
         $dataSet->AddSerie("Serie1");
         $dataSet->SetAbsciseLabelSerie("Serie2");
         //Initialise the graph
         $chart = new pChart($xSize, $ySize);
         $chart->setFontProperties($pChartPath . "tahoma.ttf", $fontSize);
         $chart->setGraphArea($x1, $y1, $x2, $y2);
         //set the y axis scale.
         $chart->setFixedScale(0, $maxScale, 1);
         $chart->drawFilledRoundedRectangle(0, 0, $xSize, $ySize, 5, 240, 240, 240);
         $chart->drawRoundedRectangle(0, 0, $xSize, $ySize, 5, 230, 230, 230);
         $chart->drawGraphArea(255, 255, 255, TRUE);
         $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 1, FALSE, $divisionWidth, $monetaryformatting);
         $chart->drawGrid(4, TRUE, 230, 230, 230, 50);
         //set colors.
         $chart->setColorShades($shades, self::$_colors);
         //Draw the bar chart
         $chart->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), TRUE, 80, true);
         //get the series values and write at top.
         $chart->setColorPalette(0, 0, 0, 255);
         $dataDesc = $dataSet->GetDataDescription();
         $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), $dataDesc['Values'], $monetaryformatting, $angleOfIncline);
         //Write the title
         if ($legend) {
             $chart->setFontProperties($pChartPath . "tahoma.ttf", 10);
             $chart->drawTitle(10, 20, $legend, 50, 50, 50);
         }
         if ($xname) {
             $chart->setFontProperties($pChartPath . "tahoma.ttf", 8);
             $chart->drawTitle(0, 90, $xname, 2, 0, 2);
         }
         if ($yname) {
             $chart->setFontProperties($pChartPath . "tahoma.ttf", 8);
             $chart->drawTitle(40, 290, $yname, 2, 0, 20);
         }
         $fileName = "pChartByMonth{$chartCount}" . time() . '.png';
         $chart->Render($uploadDirPath . $fileName);
         //get the file path.
         $filesValues[$chartIndex]['file_name'] = $uploadDirURL . $fileName;
         //get the co-ordinates
         $coords = $chart->coordinates();
         //format the coordinates to make graph clickable.
         $position = 0;
         $chartCoords = array();
         foreach ($chartValues['values'] as $name => $value) {
             $chartCoords[$name] = implode(',', array($coords['xCoords'][$position], $coords['yCoords'][$position], $coords['xCoords'][$position] + $divisionWidth / 2, $y2));
             $position++;
         }
         $filesValues[$chartIndex]['coords'] = $chartCoords;
         //free the chart and data objects.
         unset($chart);
         unset($dataSet);
     }
     return $filesValues;
 }