Пример #1
0
 /**
  * Gets a validation for a given item
  *
  * @param integer $itemID The item we want the validations for
  * @param CMS_user $user The user we want the validations for
  * @param integer $getEditionType The validation type we want.
  *  by default function return RESOURCE_EDITION_LOCATION then RESOURCE_EDITION_CONTENT then RESOURCE_EDITION_SIBLINGSORDER
  * @return array(CMS_resourceValidation) The resourceValidations objects, false if none found for the given user.
  * @access public
  */
 function getValidationByID($itemID, &$user, $getEditionType = false)
 {
     if (!is_a($user, "CMS_profile_user")) {
         $this->raiseError("User is not a valid CMS_profile_user object");
         return false;
     }
     if (!$user->hasValidationClearance($this->_codename)) {
         return false;
     }
     if (is_array($this->_resourceInfo) && $this->_resourceInfo) {
         $primaryResource = $this->getPrimaryResourceInfo();
         if (!$getEditionType) {
             $getEditionType = RESOURCE_EDITION_LOCATION + RESOURCE_EDITION_CONTENT;
         }
         $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t" . $primaryResource['key'] . " as id,\n\t\t\t\t\t\tlocation_rs as location,\n\t\t\t\t\t\tproposedFor_rs as proposedFor,\n\t\t\t\t\t\tvalidationsRefused_rs as validationsRefused,\n\t\t\t\t\t\teditions_rs as editions\n\t\t\t\t\tfrom\n\t\t\t\t\t\t" . $primaryResource['tableName'] . "_edited,\n\t\t\t\t\t\tresources,\n\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $primaryResource['key'] . " = '" . $itemID . "'\n\t\t\t\t\t\tand " . $primaryResource['resource'] . " = id_res\n\t\t\t\t\t\tand status_res = id_rs\n\t\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows() == 1) {
             $r = $q->getArray();
             $id = $r["id"];
             //search the type of edition
             //RESOURCE_EDITION_LOCATION
             if ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] != 0 && !($r["validationsRefused"] & RESOURCE_EDITION_LOCATION) && $getEditionType & RESOURCE_EDITION_LOCATION) {
                 $language = $user->getLanguage();
                 $item = $this->getResourceByID($id);
                 $validation = new CMS_resourceValidation($this->_codename, RESOURCE_EDITION_LOCATION, $item);
                 if (!$validation->hasError()) {
                     $validation->setValidationTypeLabel($language->getMessage($this->getModuleValidationLabel("locationChange"), false, $this->_codename));
                     $validation->setValidationLabel($language->getMessage($this->getModuleValidationLabel("locationChangeOfResource"), false, $this->_codename) . " " . $item->{$this->_resourceNameMethod}());
                     $validation->setValidationShortLabel($item->{$this->_resourceNameMethod}());
                     if ($this->_resourcePrevizFile) {
                         $validation->addHelpUrl($language->getMessage($this->getModuleValidationLabel("URLPreviz"), false, $this->_codename), PATH_ADMIN_MODULES_WR . "/" . $this->_codename . "/" . $this->_resourcePrevizFile . ".php?item=" . $id);
                     }
                     $validation->setEditorsStack($item->getEditorsStack());
                     return $validation;
                 } else {
                     return false;
                 }
                 //RESOURCE_EDITION_CONTENT
             } elseif ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] == 0 && ($r["editions"] & RESOURCE_EDITION_CONTENT && !($r["validationsRefused"] & RESOURCE_EDITION_CONTENT)) && $getEditionType & RESOURCE_EDITION_CONTENT) {
                 $language = $user->getLanguage();
                 $editions = $r["editions"];
                 //RESOURCE_EDITION_CONTENT
                 $item = $this->getResourceByID($id);
                 $validation = new CMS_resourceValidation($this->_codename, $editions, $item);
                 if (!$validation->hasError()) {
                     $validation->setValidationTypeLabel($language->getMessage($this->getModuleValidationLabel("edition"), false, $this->_codename));
                     $validation->setValidationLabel($language->getMessage($this->getModuleValidationLabel("editionOfResource"), false, $this->_codename) . " " . $item->{$this->_resourceNameMethod}());
                     $validation->setValidationShortLabel($item->{$this->_resourceNameMethod}());
                     if ($this->_resourcePrevizFile) {
                         $validation->addHelpUrl($language->getMessage($this->getModuleValidationLabel("URLPreviz"), false, $this->_codename), PATH_ADMIN_MODULES_WR . "/" . $this->_codename . "/" . $this->_resourcePrevizFile . "?item=" . $id);
                     }
                     $validation->setEditorsStack($item->getEditorsStack());
                     return $validation;
                 } else {
                     return false;
                 }
             }
         } elseif ($q->getNumRows() == 0) {
             return false;
         } else {
             $this->raiseError("Can't have more than one item for a given ID");
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * Gets a validation for a given item
  *
  * @param integer $itemID The item we want the validations for
  * @param CMS_user $user The user we want the validations for
  * @param integer $getEditionType The validation type we want.
  *  by default function return RESOURCE_EDITION_LOCATION then RESOURCE_EDITION_CONTENT then RESOURCE_EDITION_SIBLINGSORDER
  * @return array(CMS_resourceValidation) The resourceValidations objects, false if none found for the given user.
  * @access public
  */
 function getValidationByID($itemID, &$user, $getEditionType = false)
 {
     if (!$user instanceof CMS_profile_user) {
         $this->raiseError("User is not a valid CMS_profile_user object");
         return false;
     }
     if (!$user->hasValidationClearance($this->_codename)) {
         return false;
     }
     if (CMS_poly_object_catalog::hasPrimaryResource($this->getCodename())) {
         //get object type ID
         $objectID = CMS_poly_object_catalog::getPrimaryResourceObjectType($this->getCodename());
         //get viewvable objects list for current user
         if (CMS_poly_object_catalog::objectHasCategories($objectID)) {
             $objects = CMS_poly_object_catalog::getAllObjects($objectID, false, array(), false);
             //$where = (is_array($objects) && $objects) ? ' and objectID in ('.implode(',',$objects).')' : '';
             if (is_array($objects) && $objects) {
                 $where = ' and objectID in (' . implode(',', $objects) . ')';
             } else {
                 return false;
             }
         } else {
             $where = '';
         }
         $this->getPrimaryResourceDefinition();
         if (!$getEditionType) {
             $getEditionType = RESOURCE_EDITION_LOCATION + RESOURCE_EDITION_CONTENT;
         }
         $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\tobjectID as id,\n\t\t\t\t\t\tlocation_rs as location,\n\t\t\t\t\t\tproposedFor_rs as proposedFor,\n\t\t\t\t\t\tvalidationsRefused_rs as validationsRefused,\n\t\t\t\t\t\teditions_rs as editions,\n\t\t\t\t\t\tmod_subobject_integer_edited.id as fieldID\n\t\t\t\t\tfrom\n\t\t\t\t\t\tmod_subobject_integer_edited,\n\t\t\t\t\t\tmod_object_polyobjects,\n\t\t\t\t\t\tresources,\n\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID = '" . $itemID . "'\n\t\t\t\t\t\tand value = id_res\n\t\t\t\t\t\tand object_type_id_moo = '" . $objectID . "'\n\t\t\t\t\t\tand id_moo = objectID\n\t\t\t\t\t\tand objectFieldID = 0\n\t\t\t\t\t\tand objectSubFieldID = 0\n\t\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\t\t{$where}\n\t\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows() >= 1) {
             $r = $q->getArray();
             $id = $r["id"];
             //here, this is an ugly hack to resolve a strange bug (multiple resources for an unique object).
             //not time to found the real cause for now ...
             if ($q->getNumRows() > 1) {
                 while ($exceptionFiledID = $q->getValue('fieldID')) {
                     $sql_delete = "delete from mod_subobject_integer_edited where id = '" . $exceptionFiledID . "'";
                     $q_delete = new CMS_query($sql_delete);
                 }
             }
             //search the type of edition
             //RESOURCE_EDITION_LOCATION
             if ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] != 0 && !($r["validationsRefused"] & RESOURCE_EDITION_LOCATION) && $getEditionType & RESOURCE_EDITION_LOCATION) {
                 $language = $user->getLanguage();
                 $item = $this->getResourceByID($id);
                 $validation = new CMS_resourceValidation($this->_codename, RESOURCE_EDITION_LOCATION, $item);
                 if (!$validation->hasError()) {
                     $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_LOCATIONCHANGE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME));
                     $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_LOCATIONCHANGE_OFRESOURCE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME) . " " . io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $validation->setValidationShortLabel(io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $previzURL = $item->getPrevizPageURL();
                     if ($previzURL) {
                         $validation->addHelpUrl($language->getMessage(self::MESSAGE_PAGE_ACTION_PREVIZ), $previzURL);
                     }
                     $validation->setEditorsStack($item->getEditorsStack());
                     return $validation;
                 } else {
                     return false;
                 }
                 //RESOURCE_EDITION_CONTENT
             } elseif ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] == 0 && ($r["editions"] & RESOURCE_EDITION_CONTENT && !($r["validationsRefused"] & RESOURCE_EDITION_CONTENT)) && $getEditionType & RESOURCE_EDITION_CONTENT) {
                 $language = $user->getLanguage();
                 $editions = $r["editions"];
                 //RESOURCE_EDITION_CONTENT
                 $item = $this->getResourceByID($id);
                 $validation = new CMS_resourceValidation($this->_codename, $editions, $item);
                 if (!$validation->hasError()) {
                     $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_EDITION, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME));
                     $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_POLYMOD_VALIDATION_EDITION_OFRESOURCE, array($this->_primaryResourceObjectDefinition->getLabel($language)), MOD_POLYMOD_CODENAME) . " " . io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $validation->setValidationShortLabel(io::decodeEntities($item->{$this->_resourceNameMethod}()));
                     $previzURL = $item->getPrevizPageURL();
                     if ($previzURL) {
                         $validation->addHelpUrl($language->getMessage(self::MESSAGE_PAGE_ACTION_PREVIZ), $previzURL);
                     }
                     $validation->setEditorsStack($item->getEditorsStack());
                     return $validation;
                 } else {
                     return false;
                 }
             }
         } elseif ($q->getNumRows() == 0) {
             return false;
         } else {
             $this->raiseError("Can't have more than one item for a given ID");
             return false;
         }
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * Gets the module validations for the given editions and user
  *
  * @param CMS_user $user The user we want the validations for
  * @param integer $editions The editions we want the validations of
  * @return array(CMS_resourceValidation) The resourceValidations objects, false if noen found
  * @access public
  */
 function getValidationsByEditions(&$user, $editions)
 {
     $language = $user->getLanguage();
     $validations = array();
     $nb_loc = $nb_cont = $nb_ord = '0';
     if ($editions & RESOURCE_EDITION_LOCATION) {
         //Location change
         $sql_loc = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs != 0\n\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_LOCATION . ")\n\t\t\t";
         $q_loc = new CMS_query($sql_loc);
         $nb_loc = $q_loc->getNumRows();
     }
     if ($editions & RESOURCE_EDITION_CONTENT || $editions & RESOURCE_EDITION_BASEDATA) {
         //content and/or base data change
         $sql_cont = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag,\n\t\t\t\t\teditions_rs\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs = 0\n\t\t\t\t\tand ((editions_rs & " . RESOURCE_EDITION_CONTENT . "\n\t\t\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_CONTENT . "))\n\t\t\t\t\t\tor (editions_rs & " . RESOURCE_EDITION_BASEDATA . "\n\t\t\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_BASEDATA . ")))\n\t\t\t";
         $q_cont = new CMS_query($sql_cont);
         $nb_cont = $q_cont->getNumRows();
     }
     if ($editions & RESOURCE_EDITION_SIBLINGSORDER) {
         //siblings order change
         $sql_ord = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs = 0\n\t\t\t\t\tand editions_rs & " . RESOURCE_EDITION_SIBLINGSORDER . "\n\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_SIBLINGSORDER . ")\n\t\t\t";
         $q_ord = new CMS_query($sql_ord);
         $nb_ord = $q_ord->getNumRows();
     }
     if ($editions & RESOURCE_EDITION_MOVE) {
         //siblings order change
         $sql_mov = "\n\t\t\t\tselect\n\t\t\t\t\tid_pag\n\t\t\t\tfrom\n\t\t\t\t\tpages,\n\t\t\t\t\tresources,\n\t\t\t\t\tresourceStatuses\n\t\t\t\twhere\n\t\t\t\t\tresource_pag = id_res\n\t\t\t\t\tand status_res = id_rs\n\t\t\t\t\tand location_rs = '" . RESOURCE_LOCATION_USERSPACE . "'\n\t\t\t\t\tand proposedFor_rs = 0\n\t\t\t\t\tand editions_rs & " . RESOURCE_EDITION_MOVE . "\n\t\t\t\t\tand not (validationsRefused_rs & " . RESOURCE_EDITION_MOVE . ")\n\t\t\t";
         $q_mov = new CMS_query($sql_mov);
         $nb_mov = $q_mov->getNumRows();
     }
     //Location change
     if ($nb_loc) {
         while ($id = $q_loc->getValue("id_pag")) {
             //check if the page is editable by the user. If not, can't validate it
             if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) {
                 continue;
             }
             $page = $this->getResourceByID($id);
             $validation = new CMS_resourceValidation($this->_codename, RESOURCE_EDITION_LOCATION, $page);
             if (!$validation->hasError()) {
                 $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_LOCATIONCHANGE));
                 $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_LOCATIONCHANGE_OFPAGE) . " " . $page->getTitle());
                 $validation->setValidationShortLabel($page->getTitle());
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id);
                 if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) {
                     $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL());
                 }
                 //Back to edition location
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');');
                 $validation->setEditorsStack($page->getEditorsStack());
                 $validations[] = $validation;
             }
         }
     }
     //content and/or base data change
     if ($nb_cont) {
         while ($data = $q_cont->getArray()) {
             $id = $data["id_pag"];
             //check if the page is editable by the user. If not, can't validate it
             if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) {
                 continue;
             }
             $editions = RESOURCE_EDITION_CONTENT + RESOURCE_EDITION_BASEDATA;
             $page = $this->getResourceByID($id);
             $validation = new CMS_resourceValidation($this->_codename, $editions, $page);
             if (!$validation->hasError()) {
                 $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_EDITION));
                 $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_EDITION_OFPAGE) . " " . $page->getTitle());
                 $validation->setValidationShortLabel($page->getTitle());
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id);
                 if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) {
                     $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL());
                 }
                 //Back to edition location
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');');
                 $validation->setEditorsStack($page->getEditorsStack());
                 $validations[] = $validation;
             }
         }
     }
     //siblings order change
     if ($nb_ord) {
         while ($data = $q_ord->getArray()) {
             $id = $data["id_pag"];
             //check if the page is editable by the user. If not, can't validate it
             if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) {
                 continue;
             }
             $editions = RESOURCE_EDITION_SIBLINGSORDER;
             $page = $this->getResourceByID($id);
             $validation = new CMS_resourceValidation($this->_codename, $editions, $page);
             if (!$validation->hasError()) {
                 $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_SIBLINGSORDER));
                 $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_SIBLINGSORDER_OFPAGE) . " " . $page->getTitle());
                 $validation->setValidationShortLabel($page->getTitle());
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id);
                 if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) {
                     $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL());
                 }
                 //Back to edition location
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');');
                 $validation->setEditorsStack($page->getEditorsStack());
                 $validations[] = $validation;
             }
         }
     }
     //move change
     if ($nb_mov) {
         while ($data = $q_mov->getArray()) {
             $id = $data["id_pag"];
             //check if the page is editable by the user. If not, can't validate it
             if (!$user->hasPageClearance($id, CLEARANCE_PAGE_EDIT)) {
                 continue;
             }
             $editions = RESOURCE_EDITION_MOVE;
             $page = $this->getResourceByID($id);
             $validation = new CMS_resourceValidation($this->_codename, $editions, $page);
             if (!$validation->hasError()) {
                 $validation->setValidationTypeLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_MOVE));
                 $validation->setValidationLabel($language->getMessage(self::MESSAGE_MOD_STANDARD_VALIDATION_MOVE_OFPAGE) . " " . $page->getTitle());
                 $validation->setValidationShortLabel($page->getTitle());
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_PREVIZ), PATH_ADMIN_WR . '/page-previsualization.php?currentPage=' . $id);
                 if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC) {
                     $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_ONLINE), $page->getURL());
                 }
                 //Back to edition location
                 $validation->addHelpUrl($language->getMessage(self::MESSAGE_MOD_STANDARD_URL_EDIT), PATH_ADMIN_WR . '/page-content.php?page=' . $id, "_self", 'Automne.tabPanels.setActiveTab(\'edit\');Automne.utils.getPageById(' . $id . ');');
                 $validation->setEditorsStack($page->getEditorsStack());
                 $validations[] = $validation;
             }
         }
     }
     return $validations;
 }