function &doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false) { global $smart_previous_page; $this->postDataToObject($smartObj); if ($smartObj->isNew()) { $redirect_msg = $created_success_msg; } else { $redirect_msg = $modified_success_msg; } // Check if there were uploaded files if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) { include_once XOOPS_ROOT_PATH . "/modules/smartobject/class/smartuploader.php"; $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight); foreach ($_FILES as $name => $file_array) { if (isset($file_array['name']) && $file_array['name'] != "" && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) { if ($uploaderObj->fetchMedia($name)) { $uploaderObj->setTargetFileName(time() . "_" . $uploaderObj->getMediaName()); if ($uploaderObj->upload()) { // Find the related field in the SmartObject $related_field = str_replace('upload_', '', $name); $uploadedArray[] = $related_field; //si c'est un fichier Rich if ($smartObj->vars[$related_field]['data_type'] == XOBJ_DTYPE_FILE) { $object_fileurl = $smartObj->getUploadDir(); $fileObj = $smartObj->getFileObj($related_field); $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName()); $fileObj->setVar('caption', $_POST['caption_' . $related_field]); $fileObj->setVar('description', $_POST['desc_' . $related_field]); $smartObj->storeFileObj($fileObj); //todo : catch errors $smartObj->setVar($related_field, $fileObj->getVar('fileid')); } else { $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field); unlink($old_file); $smartObj->setVar($related_field, $uploaderObj->getSavedFileName()); } } else { $smartObj->setErrors($uploaderObj->getErrors(false)); } } else { $smartObj->setErrors($uploaderObj->getErrors(false)); } } } } if ($debug) { $storeResult = $this->handler->insertD($smartObj); } else { $storeResult = $this->handler->insert($smartObj); } if ($storeResult) { if ($this->handler->getPermissions()) { $smartpermissions_handler = new SmartobjectPermissionHandler($this->handler); $smartpermissions_handler->storeAllPermissionsForId($smartObj->id()); } } if ($redirect_page === null) { return $smartObj; } else { if (!$storeResult) { redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors()); } $redirect_page = $redirect_page ? $redirect_page : smart_get_page_before_form(); redirect_header($redirect_page, 2, $redirect_msg); } }
/** * insert a new Partner in the database * * @param object $partner reference to the {@link SmartpartnerPartner} object * @param bool $force * @return bool FALSE if failed, TRUE if already present and unchanged or successful */ function insert(&$partner, $force = false) { if (strtolower(get_class($partner)) != strtolower($this->className)) { return false; } if (!$partner->isDirty()) { return true; } if (!$partner->cleanVars()) { return false; } foreach ($partner->cleanVars as $k => $v) { ${$k} = $v; } if ($partner->isNew()) { $sql = sprintf("INSERT INTO %s (id, weight, hits, hits_page, url, image, image_url, title, datesub, summary, description, contact_name, contact_email, contact_phone, adress, `status`, `last_update`, `email_priv`, `phone_priv`, `adress_priv`, `showsummary`) VALUES ('', %u, %u, %u, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %u, %u, %u, %u, %u, %u)", $this->table, $weight, $hits, $hits_page, $this->db->quoteString($url), $this->db->quoteString($image), $this->db->quoteString($image_url), $this->db->quoteString($title), time(), $this->db->quoteString($summary), $this->db->quoteString($description), $this->db->quoteString($contact_name), $this->db->quoteString($contact_email), $this->db->quoteString($contact_phone), $this->db->quoteString($adress), $status, time(), $email_priv, $phone_priv, $adress_priv, $showsummary); } else { $sql = sprintf("UPDATE %s SET weight = %u, hits = %u, hits_page = %u, url = %s, image = %s, image_url = %s, title = %s, datesub = %s, summary = %s, description = %s, contact_name = %s, contact_email = %s, contact_phone = %s, adress = %s, `status` = %u, `last_update` = %u, `email_priv` = %u, `phone_priv` = %u, `adress_priv` = %u, `showsummary` = %u WHERE id = %u", $this->table, $weight, $hits, $hits_page, $this->db->quoteString($url), $this->db->quoteString($image), $this->db->quoteString($image_url), $this->db->quoteString($title), $this->db->quoteString($datesub), $this->db->quoteString($summary), $this->db->quoteString($description), $this->db->quoteString($contact_name), $this->db->quoteString($contact_email), $this->db->quoteString($contact_phone), $this->db->quoteString($adress), $status, time(), $email_priv, $phone_priv, $adress_priv, $showsummary, $id); } //echo "<br />" . $sql . "<br />";exit; if (false != $force) { $result = $this->db->queryF($sql); } else { $result = $this->db->query($sql); } if (!$result) { return false; } if ($partner->isNew()) { $partner->assignVar('id', $this->db->getInsertId()); } global $smartpartner_partner_cat_link_handler; $criteria = new CriteriaCompo(); $criteria->add(new Criteria('partnerid', $partner->getVar('id'))); $links = $smartpartner_partner_cat_link_handler->getObjects($criteria); $categoryid = explode('|', $partner->getVar('categoryid')); $parent_array = array(); foreach ($links as $link) { if (!in_array($link->getVar('categoryid'), $categoryid)) { $smartpartner_partner_cat_link_handler->delete($link); } else { $parent_array[] = $link->getVar('categoryid'); } } foreach ($categoryid as $cat) { if (!in_array($cat, $parent_array)) { $linkObj = $smartpartner_partner_cat_link_handler->create(); $linkObj->setVar('partnerid', $partner->getVar('id')); $linkObj->setVar('categoryid', $cat); $smartpartner_partner_cat_link_handler->insert($linkObj); } } if (isset($_POST['partial_view']) || isset($_POST['full_view'])) { $smartpermissions_handler = new SmartobjectPermissionHandler($this); $smartpermissions_handler->storeAllPermissionsForId($partner->id()); } return true; }