Je travail sous joomla et j'ai besoin de mettre en place un système de petites annonces...Seul bémol, je dois être la seule à pouvoir poster des annonces or pour le moment n'importe qui peut s'enregistrer pour poster une annonce. En tant que grande débutante en PHP, j'ai besoin d'un coup de main ! J'ai identifier le code à changer mais je suis un peu perdue. Que dois-je modifier pour empêcher un internaute de poster une annonce?
Code : Tout sélectionner
/**
* Gets an add link for the user
* @return void
*/
function getAddLinkforUser($option) {
$db = &JFactory::getDBO();
$user =& JFactory::getUser();
$user_id = $user->get( 'id' );
$gid = $user->get('gid');
$model = getModelforUser($user_id);
$canadd = 1;
$query = "SELECT * FROM #__ksads_config WHERE id ='1'";
$db->setQuery($query);
$conf = $db->loadObject();
//Has user reached max number of allowed ads?
if ($model->ads_per_period > 0 && $user_id) {
$query = "SELECT * FROM #__ksads_ads WHERE user_id ='$user_id' AND published = 1";
$db->setQuery($query);
$rows = $db->loadObjectList();
if (count($rows) >= $model->ads_per_period) {
$canadd = 0;
$msg = JText::_('Max number of ads reached');
}
}
//Can user place ads?
$accid = ($user_id > 0) ? $gid : 0;
if ($conf->access > $accid) {
$msg = JText::_('Placing Ads not allowed');
if ($accid == 0) {
$msg = '<a href="'.trim($conf->loginlink).'">'.JText::_("Please log in").'</a>'.JText::_('to submit an ad');
}
$canadd = 0;
}
//Ads are allowed, generate link and throw message
if ($canadd == 1) {
$msg = JText::_("Advertise an Item");
$link = JRoute::_('index.php?option=' . $option . '&task=add');
$addlink = '<a href="' . $link . '">'.$msg.'</a>';
} else {
$addlink = $msg;
}
return $addlink;
}
function getNextHigher($current, $option)
{
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__ksads_cats WHERE id = ". $current;
$db->setQuery($query);
$result = $db->loadObject();
$parent = $result->pid;
if ($parent == 0) {
// We are already on the top
$parentlink = JRoute::_('index.php?option=' . $option);
$parentname = '';
} else {
$parentlink = 'index.php?option=' . $option . '&pid=' . $parent . '&task=showcats';
// Get the name of the parent-parent category
$query = "SELECT * FROM #__ksads_cats WHERE id = ". $parent;
$db->setQuery($query);
$result2 = $db->loadObject();
$parentname = $result2->cat_name;
}
return $parentname.",".$parentlink.",".$result->cat_name;
}
function myAds($option)
{
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__ksads_config WHERE id ='1'";
$db->setQuery($query);
$conf = $db->loadObject();
$cur = $conf->currency;
$query = "SELECT * FROM #__ksads_currencies WHERE id = $cur";
$db->setQuery($query);
$curr = $db->loadObject();
$currency = $curr->currency_code;
$user =& JFactory::getUser();
$user_id = $user->get( 'id' );
$query = "SELECT * FROM #__ksads_ads WHERE user_id = '" . $user_id . "' ORDER BY ad_name";
$db->setQuery($query);
$rows = $db->loadObjectList();
if ($db->getErrorNum())
{
echo $db->stderr();
return false;