/**
  * Move the data of a resource from one data location to another.
  * May be used by every module, provided it respects the naming rules described in the modules HOWTO
  *
  * @param string $module, The module codename
  * @param integer $resourceID The DB ID of the resource whose data we want to move
  * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION
  * @param string $locationTo The ending location, among  the available RESOURCE_DATA_LOCATION
  * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur
  * @return boolean true on success, false on failure
  * @access public
  * @static
  */
 function moveResourceData($module, $resourceID, $locationFrom, $locationTo, $copyOnly = false)
 {
     //get all datas locations
     $locations = CMS_resource::getAllDataLocations();
     if (!in_array($locationFrom, $locations)) {
         CMS_grandFather::raiseError("LocationFrom is not a valid location : " . $locationFrom);
         return false;
     }
     if (!in_array($locationTo, $locations)) {
         CMS_grandFather::raiseError("LocationTo is not a valid location : " . $locationTo);
         return false;
     }
     if (!sensitiveIO::IsPositiveInteger($resourceID)) {
         CMS_grandFather::raiseError("ResourceID must be a positive integer : " . $resourceID);
         return false;
     }
     //first move DB datas
     $tables_prefixes = array('mod_subobject_date_', 'mod_subobject_integer_', 'mod_subobject_string_', 'mod_subobject_text_');
     foreach ($tables_prefixes as $table_prefix) {
         //delete all in the destination table and insert new ones
         if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
             $sql = "\n\t\t\t\t\treplace into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
         if (!$copyOnly) {
             //delete from the starting table
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
     }
     //second, move the files
     $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
     //cut here if the locationFromDir doesn't exists. That means the module doesn't have files
     if (!$locationFromDir->exists()) {
         return true;
     }
     if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
         $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
         //cut here if the locationToDir doesn't exists.
         if (!$locationToDir->exists()) {
             CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo);
             return false;
         }
         //delete all files of the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     $this->raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
         //then copy or move them to the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file);
                 if ($copyOnly) {
                     if (!CMS_file::copyTo($file, $to)) {
                         $this->raiseError("Can't copy file " . $file . " to " . $to);
                         return false;
                     }
                 } else {
                     if (!CMS_file::moveTo($file, $to)) {
                         $this->raiseError("Can't move file " . $file . " to " . $to);
                         return false;
                     }
                 }
                 //then chmod new file
                 CMS_file::chmodFile(FILES_CHMOD, $to);
             }
         }
     } else {
         //then get all files of the locationFromDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     $this->raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * Writes the page into persistence (MySQL for now), along with base data.
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function writeToPersistence()
 {
     parent::writeToPersistence();
     $isNew = $this->_pageID === NULL;
     // Inform modules of the page creation
     $modules = CMS_modulesCatalog::getAll('id');
     foreach ($modules as $codename => $module) {
         if (method_exists($module, 'pagePreSave')) {
             $module->pagePreSave($this, $isNew);
         }
     }
     //save page data
     $sql_fields = "\n\t\t\tresource_pag='" . parent::getID() . "',\n\t\t\tremindedEditorsStack_pag='" . SensitiveIO::sanitizeSQLString($this->_remindedEditors->getTextDefinition()) . "',\n\t\t\tlastReminder_pag='" . $this->_lastReminder->getDBValue() . "',\n\t\t\ttemplate_pag='" . $this->_templateID . "',\n\t\t\tlastFileCreation_pag='" . $this->_lastFileCreation->getDBValue() . "',\n\t\t\turl_pag='" . SensitiveIO::sanitizeSQLString($this->_pageURL) . "',\n\t\t\tprotected_pag='" . ($this->_protected ? 1 : 0) . "',\n\t\t\thttps_pag='" . ($this->_https ? 1 : 0) . "'\n\t\t";
     if ($this->_pageID) {
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tpages\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_pag='" . $this->_pageID . "'\n\t\t\t";
     } else {
         $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tpages\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields;
     }
     $q = new CMS_query($sql);
     if ($q->hasError()) {
         return false;
     } elseif (!$this->_pageID) {
         $this->_pageID = $q->getLastInsertedID();
     }
     //save base data if modified
     if ($this->_editedBaseData) {
         $sql_fields = "\n\t\t\t\tpage_pbd='" . $this->_pageID . "',\n\t\t\t\ttitle_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["title"]) . "',\n\t\t\t\tlinkTitle_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["linkTitle"]) . "',\n\t\t\t\tkeywords_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["keywords"]) . "',\n\t\t\t\tdescription_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["description"]) . "',\n\t\t\t\treminderPeriodicity_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["reminderPeriodicity"]) . "',\n\t\t\t\treminderOn_pbd='" . $this->_editedBaseData["reminderOn"]->getDBValue() . "',\n\t\t\t\treminderOnMessage_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["reminderOnMessage"]) . "',\n\t\t\t\tcategory_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["category"]) . "',\n\t\t\t\tauthor_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["author"]) . "',\n\t\t\t\treplyto_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["replyto"]) . "',\n\t\t\t\tcopyright_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["copyright"]) . "',\n\t\t\t\tlanguage_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["language"]) . "',\n\t\t\t\trobots_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["robots"]) . "',\n\t\t\t\tpragma_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["pragma"]) . "',\n\t\t\t\trefresh_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["refresh"]) . "',\n\t\t\t\tredirect_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["redirect"]->getTextDefinition()) . "',\n\t\t\t\trefreshUrl_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["refreshUrl"]) . "',\n\t\t\t\tmetas_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["metas"]) . "',\n\t\t\t\tcodename_pbd='" . SensitiveIO::sanitizeSQLString($this->_editedBaseData["codename"]) . "'\n\t\t\t";
         if ($this->_baseDataID) {
             $sql = "\n\t\t\t\t\tupdate\n\t\t\t\t\t\tpagesBaseData_edited\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $sql_fields . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_pbd='" . $this->_baseDataID . "'\n\t\t\t\t";
         } else {
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\tpagesBaseData_edited\n\t\t\t\t\tset\n\t\t\t\t\t\t" . $sql_fields;
         }
         $q = new CMS_query($sql);
         if (!$q->hasError() && !$this->_baseDataID) {
             $this->_baseDataID = $q->getLastInsertedID();
         }
     }
     // Inform modules of the page creation
     $modules = CMS_modulesCatalog::getAll('id');
     foreach ($modules as $codename => $module) {
         if (method_exists($module, 'pagePostSave')) {
             $module->pagePostSave($this, $isNew);
         }
     }
     return true;
 }
Beispiel #3
0
 /**
  * Gets the URL of a link towards a file managed by this application
  *
  * @param boolean $withPath If false, only returns the filename
  * @param string $module If false, only returns the filename
  * @param string $dataLocation Where does the data lies ? See CMS_resource constants
  * @param integer $relativeTo Can be web root or filesystem relative, see base constants
  * @param boolean $withFilename Should the function return the filename too or only the path ?
  * @return string The file
  * @access public
  */
 function getFileLink($withPath = false, $module = MOD_STANDARD_CODENAME, $dataLocation = RESOURCE_DATA_LOCATION_EDITED, $relativeTo = PATH_RELATIVETO_WEBROOT, $withFilename = true)
 {
     if ($withPath) {
         if (class_exists("CMS_resource")) {
             if (!SensitiveIO::isInSet($dataLocation, CMS_resource::getAllDataLocations()) || $dataLocation == RESOURCE_DATA_LOCATION_DEVNULL) {
                 $this->raiseError("DataLocation not in the valid set : " . $dataLocation);
                 return false;
             }
         } else {
             $dataLocation = RESOURCE_DATA_LOCATION_PUBLIC;
         }
         // Prepare module folder name
         $module = $module != '' ? $module . '/' : '';
         // Prepare full path
         switch ($relativeTo) {
             case PATH_RELATIVETO_WEBROOT:
                 $path = PATH_MODULES_FILES_WR . "/" . $module . $dataLocation;
                 break;
             case PATH_RELATIVETO_FILESYSTEM:
                 $path = PATH_MODULES_FILES_FS . "/" . $module . $dataLocation;
                 break;
         }
         if ($withFilename) {
             return $path . "/" . $this->_fileLink;
         } else {
             return $path;
         }
     } else {
         return $this->_fileLink;
     }
 }
Beispiel #4
0
 /**
  * Changes The page data (in the DB) from one location to another.
  *
  * @param CMS_page $resource The resource concerned by the data location change
  * @param string $locationFrom The starting location among the available RESOURCE_DATA_LOCATION
  * @param string $locationTo The ending location among the available RESOURCE_DATA_LOCATION
  * @param boolean $copyOnly If true, data is not deleted from the original location
  * @return void
  * @access private
  */
 protected function _changeDataLocation($resource, $locationFrom, $locationTo, $copyOnly = false)
 {
     if (!$resource instanceof CMS_resource) {
         $this->raiseError("Resource is not a CMS_resource");
         return false;
     }
     if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) {
         $this->raiseError("Locations are not in the set");
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Move the data of a resource from one data location to another.
  * May be used by every module, provided it respects the naming rules described in the modules HOWTO
  *
  * @param CMS_module $module The module who  want its data moved
  * @param string $tablesPrefix The prefix of the tables containing the data
  * @param string $resourceIDFieldName The name of the field containing the resource ID
  * @param integer $resourceID The DB ID of the resource whose data we want to move
  * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION
  * @param string $locationTo The ending location, among  the available RESOURCE_DATA_LOCATION
  * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur
  * @return boolean true on success, false on failure
  * @access public
  */
 static function moveResourceData(&$module, $tablesPrefix, $resourceIDFieldName, $resourceID, $locationFrom, $locationTo, $copyOnly = false)
 {
     if (!is_a($module, "CMS_module")) {
         CMS_grandFather::raiseError("Module is not a CMS_module");
         return false;
     }
     if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) {
         CMS_grandFather::raiseError("Locations are not in the set");
         return false;
     }
     //get the tables : named PREFIXXXXX_public
     $sql = "show tables";
     $q = new CMS_query($sql);
     $tables_prefixes = array();
     while ($data = $q->getArray()) {
         if (preg_match("#" . $tablesPrefix . "(.*)_public#", $data[0])) {
             $tables_prefixes[] = io::substr($data[0], 0, strrpos($data[0], "_") + 1);
         }
     }
     foreach ($tables_prefixes as $table_prefix) {
         //delete all in the destination table just incase and insert
         if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
         if (!$copyOnly) {
             //delete from the starting table
             $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
         }
     }
     //second, move the files
     $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
     //cut here if the locationFromDir doesn't exists. That means the module doesn't have files
     if (!$locationFromDir->exists()) {
         return true;
     }
     if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
         $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY);
         //cut here if the locationToDir doesn't exists.
         if (!$locationToDir->exists()) {
             CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo);
             return false;
         }
         //delete all files of the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
         //then copy or move them to the locationToDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file);
                 if ($copyOnly) {
                     if (!CMS_file::copyTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't copy file " . $file . " to " . $to);
                         return false;
                     }
                 } else {
                     if (!CMS_file::moveTo($file, $to)) {
                         CMS_grandFather::raiseError("Can't move file " . $file . " to " . $to);
                         return false;
                     }
                 }
                 //then chmod new file
                 CMS_file::chmodFile(FILES_CHMOD, $to);
             }
         }
     }
     //cleans the initial dir if not a copy
     if (!$copyOnly) {
         //then get all files of the locationFromDir
         $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT);
         if (is_array($files)) {
             foreach ($files as $file) {
                 if (!CMS_file::deleteFile($file)) {
                     CMS_grandFather::raiseError("Can't delete file " . $file);
                     return false;
                 }
             }
         }
     }
     return true;
 }
Beispiel #6
0
 /**
  * get an object value
  *
  * @param string $name : the name of the value to get
  * @param string $parameters (optional) : parameters for the value to get
  * @return mixed : the object values structure
  * @access public
  */
 function getValue($name, $parameters = '')
 {
     global $cms_language;
     // @TODOV4 : Manage language into database !
     $languages = array();
     $languages['fr'] = array('January' => 'Janvier', 'February' => 'Février', 'March' => 'Mars', 'April' => 'Avril', 'May' => 'Mai', 'June' => 'Juin', 'July' => 'Juillet', 'August' => 'Août', 'September' => 'Septembre', 'October' => 'Octobre', 'November' => 'Novembre', 'December' => 'Décembre', 'Monday' => 'Lundi', 'Tuesday' => 'Mardi', 'Wednesday' => 'Mercredi', 'Thursday' => 'Jeudi', 'Friday' => 'Vendredi', 'Saturday' => 'Samedi', 'Sunday' => 'Dimanche', 'Jan' => 'Jan', 'Feb' => 'Fév', 'Mar' => 'Mar', 'Apr' => 'Avr', 'May' => 'Mai', 'Jun' => 'Jui', 'Jul' => 'Jui', 'Aug' => 'Aoû', 'Sep' => 'Sep', 'Oct' => 'Oct', 'Nov' => 'Nov', 'Dec' => 'Déc', 'Mon' => 'Lun', 'Tue' => 'Mar', 'Wed' => 'Mer', 'Thu' => 'Jeu', 'Fri' => 'Ven', 'Sat' => 'Sam', 'Sun' => 'Dim');
     switch ($name) {
         case 'id':
             return (string) $this->_ID;
             break;
         case 'label':
             if ($parameters == 'js') {
                 return sensitiveIO::sanitizeJSString($this->getLabel());
             } else {
                 return $this->getLabel();
             }
             break;
         case 'objectname':
             return $this->getFieldLabel($cms_language);
             break;
         case 'objectdescription':
             return $this->getFieldDesc($cms_language);
             break;
         case 'objecttype':
             return $this->_objectID;
             break;
         case 'resource':
             if ($this->_objectResourceStatus == 1) {
                 return parent::getID();
             }
             return;
             break;
         case 'formatedDateStart':
             if ($this->_objectResourceStatus == 1) {
                 $date = parent::getPublicationDateStart();
                 if (io::strtolower($parameters) == 'rss') {
                     $date = date('r', $date->getTimeStamp());
                 } else {
                     $date = date($parameters, $date->getTimeStamp());
                     if (is_object($cms_language) && isset($languages[$cms_language->getCode()])) {
                         $date = str_replace(array_keys($languages[$cms_language->getCode()]), $languages[$cms_language->getCode()], $date);
                     }
                 }
                 return io::htmlspecialchars($date);
             }
             break;
         case 'formatedDateEnd':
             if ($this->_objectResourceStatus == 1) {
                 $date = parent::getPublicationDateEnd();
                 if (is_a($date, 'CMS_date')) {
                     if (io::strtolower($parameters) == 'rss') {
                         $date = date('r', $date->getTimeStamp());
                     } else {
                         $date = date($parameters, $date->getTimeStamp());
                         if (is_object($cms_language) && isset($languages[$cms_language->getCode()])) {
                             $date = str_replace(array_keys($languages[$cms_language->getCode()]), $languages[$cms_language->getCode()], $date);
                         }
                     }
                     return io::htmlspecialchars($date);
                 }
             }
             break;
         case 'dateStartNotNull':
             if ($this->_objectResourceStatus == 1) {
                 $date = parent::getPublicationDateStart();
                 return !$date->isNull();
             }
             break;
         case 'dateStartTimestamp':
             if ($this->_objectResourceStatus == 1) {
                 $date = parent::getPublicationDateStart();
                 return $date->getTimestamp();
             }
             break;
         case 'dateEndNotNull':
             if ($this->_objectResourceStatus == 1) {
                 $date = parent::getPublicationDateEnd();
                 return !$date->isNull();
             }
             break;
         case 'dateEndTimestamp':
             if ($this->_objectResourceStatus == 1) {
                 $date = parent::getPublicationDateEnd();
                 return $date->getTimestamp();
             }
             break;
             //field related values, may not exists ...
         //field related values, may not exists ...
         case 'fieldID':
             if (!is_a($this->_field, 'CMS_poly_object_field')) {
                 $this->raiseError("Can't get 'fieldID' value for an object which is not a field of another object ...");
                 return '';
             }
             return $this->_field->getID();
             break;
         case 'description':
             if (!is_a($this->_field, 'CMS_poly_object_field')) {
                 $this->raiseError("Can't get 'description' value for an object which is not a field of another object ...");
                 return '';
             }
             return io::htmlspecialchars($this->_field->getFieldDescription($cms_language));
             break;
         case 'required':
             if (!is_a($this->_field, 'CMS_poly_object_field')) {
                 $this->raiseError("Can't get 'required' value for an object which is not a field of another object ...");
                 return false;
             }
             return $this->_field->getValue("required") ? true : false;
             break;
         case 'fieldname':
             if (!is_a($this->_field, 'CMS_poly_object_field')) {
                 $this->raiseError("Can't get 'fieldname' value for an object which is not a field of another object ...");
                 return '';
             }
             //get label of current field
             $fieldLabel = new CMS_object_i18nm($this->_field->getValue("labelID"));
             return $fieldLabel->getValue($cms_language->getCode());
             break;
         default:
             $this->raiseError("Unknown value to get : " . $name);
             return false;
             break;
     }
 }
 /**
  * Move the clientSpaces data from one location to another for a template
  *
  * @param integer $tagID the tag ID of the client space tag
  * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION
  * @param string $locationTo The ending location, among  the available RESOURCE_DATA_LOCATION
  * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur
  * @param boolean $forceblank If set to false, the page will be checked before removing all content of the clientspace to alert user and get confirmation. In this case, method return false until this parameter is set to true
  * @return boolean true on success, false on failure
  * @access public
  */
 static function moveClientSpaces($templateID, $locationFrom, $locationTo, $copyOnly = false, $forceblank = false)
 {
     if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) {
         CMS_grandFather::raiseError("Locations are not in the set");
         return false;
     }
     switch ($locationFrom) {
         case RESOURCE_DATA_LOCATION_ARCHIVED:
             $table_from = "mod_standard_clientSpaces_archived";
             break;
         case RESOURCE_DATA_LOCATION_DELETED:
             $table_from = "mod_standard_clientSpaces_deleted";
             break;
         case RESOURCE_DATA_LOCATION_PUBLIC:
             $table_from = "mod_standard_clientSpaces_public";
             break;
         case RESOURCE_DATA_LOCATION_EDITED:
             $table_from = "mod_standard_clientSpaces_edited";
             break;
         case RESOURCE_DATA_LOCATION_EDITION:
             $table_from = "mod_standard_clientSpaces_edition";
             break;
     }
     switch ($locationTo) {
         case RESOURCE_DATA_LOCATION_ARCHIVED:
             $table_to = "mod_standard_clientSpaces_archived";
             break;
         case RESOURCE_DATA_LOCATION_DELETED:
             $table_to = "mod_standard_clientSpaces_deleted";
             break;
         case RESOURCE_DATA_LOCATION_PUBLIC:
             $table_to = "mod_standard_clientSpaces_public";
             break;
         case RESOURCE_DATA_LOCATION_EDITED:
             $table_to = "mod_standard_clientSpaces_edited";
             break;
         case RESOURCE_DATA_LOCATION_EDITION:
             $table_to = "mod_standard_clientSpaces_edition";
             break;
     }
     //check for blank page
     if (!$forceblank && $locationFrom == RESOURCE_DATA_LOCATION_EDITION && $locationTo == RESOURCE_DATA_LOCATION_EDITED) {
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\tcount(*) as c\n\t\t\t\tfrom\n\t\t\t\t\t" . $table_from . "\n\t\t\t\twhere\n\t\t\t\t\ttemplate_cs='" . $templateID . "'";
         $q = new CMS_query($sql);
         if ($q->getValue('c') == 0) {
             $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\tcount(*) as c\n\t\t\t\t\tfrom\n\t\t\t\t\t\t" . $table_to . "\n\t\t\t\t\twhere\n\t\t\t\t\t\ttemplate_cs='" . $templateID . "'";
             $q = new CMS_query($sql);
             if ($q->getValue('c') != 0) {
                 return false;
             }
         }
     }
     //delete all in the destination table just incase and insert
     if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) {
         $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\t" . $table_to . "\n\t\t\t\twhere\n\t\t\t\t\ttemplate_cs='" . $templateID . "'\n\t\t\t";
         $q = new CMS_query($sql);
         $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\t" . $table_to . "\n\t\t\t\t\tselect\n\t\t\t\t\t\t*\n\t\t\t\t\tfrom\n\t\t\t\t\t\t" . $table_from . "\n\t\t\t\t\twhere\n\t\t\t\t\t\ttemplate_cs='" . $templateID . "'\n\t\t\t";
         $q = new CMS_query($sql);
     }
     if (!$copyOnly) {
         //delete from the starting table
         $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\t" . $table_from . "\n\t\t\t\twhere\n\t\t\t\t\ttemplate_cs='" . $templateID . "'\n\t\t\t";
         $q = new CMS_query($sql);
     }
     return true;
 }
Beispiel #8
0
 /**
  * Writes the object data into persistence (MySQL for now), along with base data.
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function writeToPersistence()
 {
     if ($this->_hasResource()) {
         //write parent
         parent::writeToPersistence();
     }
     //save data
     $sql_fields = "";
     $count = 0;
     foreach ($this->_tableData as $label => $aData) {
         $sql_fields .= $count ? "," : '';
         $count++;
         switch ($aData[0]) {
             case 'integer':
             case 'positiveInteger':
             case 'email':
                 if (is_null($this->_tableData[$label][1])) {
                     $sql_fields .= " `" . $label . $this->_tableSufix . "`=NULL";
                 } else {
                     $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]) . "'";
                 }
                 break;
             case 'string':
             case 'html':
             case 'image':
             case 'file':
             case 'internalLink':
             case 'externalLink':
             case 'boolean':
             case 'linkType':
                 $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]) . "'";
                 break;
             case 'date':
                 $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . $this->_tableData[$label][1]->getDBValue() . "'";
                 break;
             case 'resource':
                 $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . parent::getID() . "'";
                 break;
             case 'order':
                 /*
                  * ici il manque un truc pour pouvoir attribuer automatiquement les nouveaux ordres (lors de la création d'un objet)
                  * pb : savoir à quoi il se rapporte (clause where dans les fonctions associées aux ordre)
                  * solution ? lier ça direct dans la definition de la table (tableau _tableData ou autre variable) avantages, inconvénients ??? à voir
                  */
                 $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . $this->_tableData[$label][1] . "'";
                 break;
             default:
                 if (class_exists($aData[0])) {
                     if (method_exists($this->_tableData[$label][1], "getID")) {
                         $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . $this->_tableData[$label][1]->getID() . "'";
                     } elseif (method_exists($this->_tableData[$label][1], "getTextDefinition")) {
                         $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]->getTextDefinition()) . "'";
                     } else {
                         $this->raiseError("Unknown save method for object " . $aData[0]);
                         return false;
                     }
                 } else {
                     $sql_fields .= " `" . $label . $this->_tableSufix . "`='" . SensitiveIO::sanitizeSQLString($this->_tableData[$label][1]) . "'";
                 }
                 break;
         }
     }
     $from = $this->_hasResource() ? $this->_tableName . '_edited' : $this->_tableName;
     if ($this->_ID) {
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\t" . $from . "\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\t" . $this->_idName . $this->_tableSufix . "='" . $this->_ID . "'\n\t\t\t";
     } else {
         $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\t" . $from . "\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields;
     }
     //pr($sql);
     $q = new CMS_query($sql);
     if ($q->hasError()) {
         $this->raiseError("Database write error");
         return false;
     } elseif (!$this->_ID) {
         $this->_ID = $q->getLastInsertedID();
     }
     return true;
 }