/** * Saves the content item an edit form submit * * @todo */ function save() { $app = JFactory::getApplication(); // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $user = JFactory::getUser(); $content = JTable::getInstance('contents', 'AdsmanagerTable'); $this->addModelPath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_adsmanager' . DS . 'models'); $configurationmodel = $this->getModel("configuration"); $contentmodel = $this->getModel("content"); $usermodel = $this->getModel("user"); $fieldmodel = $this->getModel("field"); $conf = $configurationmodel->getConfiguration(); $plugins = $fieldmodel->getPlugins(); $id = JRequest::getInt('id', 0); // New or Update if ($id != 0) { $content->load($id); if ($content == null || $content->userid != $user->id) { $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=list')); } $isUpdateMode = 1; if ($conf->update_validation == 1) { $redirect_text = JText::_('ADSMANAGER_INSERT_SUCCESSFULL_CONFIRM'); } else { $redirect_text = JText::_('ADSMANAGER_AD_UPDATED'); } } else { $isUpdateMode = 0; if ($conf->auto_publish == 0) { $redirect_text = JText::_('ADSMANAGER_INSERT_SUCCESSFULL_CONFIRM'); } else { $redirect_text = JText::_('ADSMANAGER_INSERT_SUCCESSFULL_PUBLISH'); } } //Check Max Ads by User $nbcats = $conf->nbcats; if (function_exists("getMaxCats")) { $nbcats = getMaxCats($conf->nbcats); } if ($nbcats <= 1) { if (function_exists("checkAuthorisedNumberAds")) { $limitAds = checkAuthorisedNumberAds($contentmodel, JRequest::getInt('category', 0)); if ($limitAds !== true) { $redirect_text = sprintf(JText::_('ADSMANAGER_MAX_NUM_ADS_PER_CATEGORY_REACHED'), $limitAds); $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=list'), $redirect_text, 'message'); } } else { if (JRequest::getInt('category', 0) != 0) { $category = JRequest::getInt('category', 0); // Need to check limit only for new ad and if category of ad is changed if ($isUpdateMode == 0 || !in_array($category, $contentmodel->getContentCategories($id))) { $nb = $contentmodel->getNbContentsOfUser($user->id, $category); //TODO : check authorised number for multi-categories $categoriesModel = $this->getModel("category"); $category = $categoriesModel->getCategory($category); if ($category->limitads !== "" && $category->limitads !== null) { if ($nb >= $category->limitads && $category->limitads != -1) { $redirect_text = sprintf(JText::_('ADSMANAGER_MAX_NUM_ADS_PER_CATEGORY_REACHED'), $category->limitads); $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=list'), $redirect_text, 'message'); } } } } } } if ($id == 0 && $user->id != "0" && $conf->nb_ads_by_user != -1) { $nb = $contentmodel->getNbContentsOfUser($user->id); if ($nb >= $conf->nb_ads_by_user) { $redirect_text = sprintf(JText::_('ADSMANAGER_MAX_NUM_ADS_REACHED'), $conf->nb_ads_by_user); $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=list'), $redirect_text, 'message'); } } //check if user can post an ad in the category selected //TODO : If multiple category if (version_compare(JVERSION, '1.6', 'ge')) { if ($nbcats <= 1) { $authorisedCategory = TPermissions::getAuthorisedCategories('write'); if (array_search(JRequest::getInt('category', 0), $authorisedCategory) === false) { $redirect_text = sprintf(JText::_('ADSMANAGER_FORBIDDEN_CATEGORY'), $conf->nb_ads_by_user); $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=list'), $redirect_text, 'message'); } } } $current = clone $content; $content->bindContent(JRequest::get('post'), JRequest::get('files'), $conf, $this->getModel("adsmanager"), $plugins); if (function_exists('bindPaidSystemContent')) { bindPaidSystemContent($content, JRequest::get('post'), JRequest::get('files'), $conf, $this->getModel("adsmanager")); } $content->current = $current; $errors = $content->getErrors(); if (count($errors) > 0) { $this->reloadForm($content); } if ($conf->metadata_mode == 'backendonly') { $content->metadata_description = JRequest::getVar('ad_text', ''); $content->metadata_keywords = str_replace(" ", ",", JRequest::getVar('ad_headline', '')); } $errorMsg = null; $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('adsmanagercontent'); try { $results = $dispatcher->trigger('ADSonContentBeforeSave', array()); } catch (Exception $e) { $errorMsg = $e->getMessage(); $this->reloadForm($content, $errorMsg); } //Creation of account if needed if ($conf->submission_type == 0 && $user->id == 0) { $username = JRequest::getVar('username', ""); $password = JRequest::getVar('password', ""); $email = JRequest::getVar('email', ""); $errorMsg = $usermodel->checkAccount($username, $password, $email, $userid, $conf); if (isset($errorMsg)) { $this->reloadForm($content, $errorMsg); } $user->id = $userid; } //Valid account or visitor are allowed to post if ($user->id != 0 || $conf->submission_type == 2) { $content->userid = $user->id; } else { //trying to save ad, without being registered return; } if (function_exists("getPaidSystemMode")) { $mode = getPaidSystemMode(); } else { $mode = "nopaidsystem"; } $total = 0; switch ($mode) { case "credits": computeCost($total, $items, $content, $conf, $isUpdateMode); if ($total == 0) { $content->save(); } else { if (checkCredits($total, $user->id) == true) { //TODO ? //generateBill($content,$total,$items,$mode,"ok"); removeCredits($user->id, $total, $items, 'Adsmanager'); $content->save(); } else { $errorMsg = sprintf(JText::_('PAIDSYSTEM_NOT_ENOUGH_CREDITS'), strtolower(getCurrencySymbol())); $this->reloadForm($content, $errorMsg); } } break; case "payperad": $adid = $content->savePending(); $content->isPending = true; computeCost($total, $items, $content, $conf, $isUpdateMode); if ($total == 0) { $content->save(); } else { $invoice_id = generateBill($content, $items, $adid); } break; case "nopaidsystem": $content->save(); break; } // We need to put "pending or new values" in the $content obj instead of $content->data $content->map(); if ($mode == "payperad" && $total > 0 && $isUpdateMode == 0) { if (@$conf->preview == 1) { $app->redirect('index.php?option=com_adsmanager&view=preview&id=' . $adid); } else { Invoicing::redirectToPayment($invoice_id); //$app->redirect( 'index.php?option=com_paidsystem&view=payment'); } } else { if (@$conf->preview == 1 && JRequest::getInt('pending', 0) == 1) { $app->redirect('index.php?option=com_adsmanager&view=preview&id=' . $adid); } else { if ($mode == "payperad" && $total > 0 && $isUpdateMode == 1) { Invoicing::redirectToPayment($invoice_id); } else { $cache =& JFactory::getCache('com_adsmanager'); $cache->clean(); if ($isUpdateMode == 0) { if ($conf->send_email_on_new_to_user == 1 && $conf->auto_publish == 1) { $contentmodel->sendMailToUser($conf->new_subject, $conf->new_text, $user, $content, $conf, "new"); } else { if ($conf->send_email_waiting_validation_to_user == 1 && $conf->auto_publish == 0) { $contentmodel->sendMailToUser($conf->waiting_validation_subject, $conf->waiting_validation_text, $user, $content, $conf, "waiting_validation"); } } if ($conf->email_on_waiting_validation == 1 && $conf->auto_publish == 0) { if (isset($conf->admin_waiting_validation_subject) && $conf->admin_waiting_validation_text) { $contentmodel->sendMailToAdmin($conf->admin_waiting_validation_subject, $conf->admin_waiting_validation_text, $user, $content, $conf, "admin_waiting_validation"); } } if ($conf->send_email_on_new == 1) { $contentmodel->sendMailToAdmin($conf->admin_new_subject, $conf->admin_new_text, $user, $content, $conf, "new"); } } else { if ($conf->update_validation == 1) { $contentmodel->sendMailToUser($conf->waiting_validation_subject, $conf->waiting_validation_text, $user, $content, $conf, "waiting_validation"); } else { if ($conf->send_email_on_update_to_user == 1) { $contentmodel->sendMailToUser($conf->update_subject, $conf->update_text, $user, $content, $conf, "update"); } } if ($conf->email_on_waiting_validation == 1 && $conf->update_validation == 1) { if (isset($conf->admin_waiting_validation_subject) && $conf->admin_waiting_validation_text) { $contentmodel->sendMailToAdmin($conf->admin_waiting_validation_subject, $conf->admin_waiting_validation_text, $user, $content, $conf, "admin_waiting_validation"); } } if ($conf->send_email_on_update == 1) { $contentmodel->sendMailToAdmin($conf->admin_update_subject, $conf->admin_update_text, $user, $content, $conf, "update"); } } JPluginHelper::importPlugin('adsmanagercontent'); try { $results = $dispatcher->trigger('ADSonContentAfterSave', array($content, $isUpdateMode, $conf)); } catch (Exception $e) { $errorMsg = $e->getMessage(); } //Redirect if ($conf->submission_type == 2) { $app->redirect(TRoute::_('index.php?option=com_adsmanager&view=list'), $redirect_text, 'message'); } else { $app->redirect(TLink::getMyAdsLink(), $redirect_text, 'message'); } } } } }
function valid() { $app = JFactory::getApplication(); $id = JRequest::getInt('id', 0); $user = JFactory::getUser(); $this->addModelPath(JPATH_ADMINISTRATOR . '/components/com_adsmanager/models'); $configurationmodel = $this->getModel("configuration"); $conf = $configurationmodel->getConfiguration(); if ($conf->auto_publish == 0) { $redirect_text = JText::_('ADSMANAGER_INSERT_SUCCESSFULL_CONFIRM'); } else { $redirect_text = JText::_('ADSMANAGER_INSERT_SUCCESSFULL_PUBLISH'); } //TODO 3.0 pending sans Invoicing if (file_exists(JPATH_ROOT . '/components/com_invoicing/lib/core.php')) { include_once JPATH_ROOT . '/components/com_invoicing/lib/core.php'; $db = JFactory::getDBO(); $db->setQuery("SELECT i.invoicing_invoice_id FROM #__invoicing_invoices as i LEFT JOIN #__invoicing_users as u ON u.invoicing_user_id = i.user_id WHERE u.user_id=" . $user->id . " AND generator_key = '" . $id . "' AND status='PENDING' ORDER BY invoicing_invoice_id DESC"); $orderid = $db->loadResult(); if ($orderid != null) { Invoicing::redirectToPayment($orderid); } } $content = JTable::getInstance('contents', 'AdsmanagerTable'); if ($content->load($id) == false) { return; } //TODO if ($content->ad_headline != "") { $isUpdateMode = 0; } else { $isUpdateMode = 1; } $content->bindPending($id); $content->saveContent(null); $contentmodel = $this->getModel("content"); $this->onAfterSave($conf, $contentmodel, $content, $isUpdateMode, $user); $this->redirectAfterSave($redirect_text, $conf, $id, $content->catid); }