Jump to content

ajouter un nouvel onglet dans le menu Back office


Rdev

Recommended Posts

Bonjour tout le monde,

 

tout est dans le titre, je veut creer un nouvel onglet dans le menu Back office

 

j'ai créé un fichier "AdminPresseController.php" et j'ai le mis dans controllers\admin

mais quand j'execute le fichier j'ai une page vide

 

 

le contenu de ma page

 

<?php
class AdminPresseControllerCore extends AdminController
{
public function display()
{
 $this->displayForm();
 $this->DisplayInfos();

}

public function displayForm($isMainTab = true)
{
 global $currentIndex;
 parent::displayForm();
 /*echo '<form name="formulaire_envoi_fichier" enctype="multipart/form-data" method="post" action="./upload.php">
  <input type="file" name="fichier_choisi">
  <br>
  <br>
  <input type="submit" name="bouton_submit" value="Envoyer le fichier">
 </form>';*/
 echo '<script language="JavaScript">
   function verifdt(){
   verdat=document.formulaire_envoi_fichier.dateop.value;
   datej= new Date()
   anneej=datej.getFullYear()+"*";
   anneej=anneej.substring(0,2)
   if (verdat.length ==6)
   verdat=verdat.substring(0,2)+"."+verdat.substring(4,2)+"."+anneej+verdat.substring(6,4);
   if (verdat.length ==8)
   verdat=verdat.substring(0,2)+"."+verdat.substring(4,2)+"."+verdat.substring(8,4);

   if(!isValidDate(verdat))
   alert("la date n\'est pas valide ou n\'est pas au bon format.\n format : jjmmaa ou jjmmaaaa ou jj.mm.aaaa");
   else
   document.formulaire_envoi_fichier.dateop.value = verdat;

 }
 function isValidDate(d) {
   var dateRegEx = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
   return d.match(dateRegEx);
 }

 </script>';
 echo '
 <form name="formulaire_envoi_fichier" enctype="multipart/form-data" method="post" action="'.$currentIndex.'&formulaire_envoi_fichier=1&conf=3&token='.$this->token.'">
 <fieldset style="width: 900px;height:500">
 <legend><img src="../img/admin/Press.gif" alt="'.$this->l('Thumbnail').'" />'.$this->l('Ajout de presse').'</legend> 
 <div class="margin-form">
  <b>Entrer la date de la presse à ajouter : </b><input name="dateop" type="text" value="'.date("d. m. Y").'" onBlur="verifdt();" maxlength="10">
  <sup>*</sup>
  <p style="padding-left:206px" class="clear">Format : 01.01.2012</p>
 </div>';
 echo '<div class="clear"> </div>


 <div style="float: left;padding:0" class="margin-form">
  <fieldset style="width: 400px;">
   <legend><img src="../img/admin/picture.gif" alt="'.$this->l('Thumbnail').'" />'.$this->l('Thumbnail').'</legend>
   <span style="font-weight: bold; font-size: 14px;">Choisissez la petite image qui apparit dans la liste.</span>
 <br>
 <br>
 <input type="file" name="thumb_img">
 <sup>*</sup>
  <p style="" class="clear">Format : 101px*138px</p>

  </fieldset>
 </div>
 <div style="float: right;padding:0" class="margin-form">
  <fieldset style="width: 400px;">
   <legend><img src="../img/admin/picture.gif" alt="'.$this->l('Grande Image').'" />'.$this->l('Grande Image').'</legend>
   <span style="font-weight: bold; font-size: 14px;">Choisissez la grande image.</span>
 <br>
 <br>
 <input type="file" name="big_img">
 <sup>*</sup>
  <p style="" class="clear">Hauteur Maximale : 552px </p>


  </fieldset>
 </div>

 <div class="clear"> </div>
 <br/><span style="color:red"><b>NB : Les images doivent être en (.jpg) ou (.jpeg)</b></span>
  <input  style="float: right" type="submit" name="bouton_submit" value="Enregistrer la presse">
  </form>
 </fieldset>
 <div class="clear"> </div>';


}
public function getPresse()
{
 $result= Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT `id`,`date`,`image`
 FROM `'._DB_PREFIX_.'presse`
 ORDER BY id DESC');
 return $result;
}
public function DelPresse($id)
{
 $result = Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'presse WHERE id = '.(int)($id));
 return $result;
}
public function DisplayInfos()
{
 global $currentIndex;
 $presses=$this->getPresse();
 //print_r($downs);
 echo '<fieldset style="width: 900px;">

 <table  style="width: 900px;" class="table" cellspacing="0" cellpadding="0">
 <thead>
  <tr  class="nodrag nodrop">
   <th  style="width: 100px;" class="item">ID</th>
   <th  style="width: 200px;"class="item">Image</th>
   <th  style="width: 400px;"class="item">Date</th>
   <th  style="width: 50px;" class="last_item">Supp.</th>
  </tr>
 </thead>
 <tfoot>';
 echo '<script>
   function confirmDelPresse(press)
   {

  return window.confirm(\''.$this->l('Voulez vous confirmer la suppression de cet element :').'\t\' + press);

   }
  </script>';
  foreach ($presses AS $presse)

   //../get-file.php?key='.$down['physically_filename'].'-'.$down['download_hash'].'
   //$link=sha1(microtime().$down['physically_filename']);
   echo '<tr class="item"><td>'.$presse['id'].'</td><td><img src="'.__PS_BASE_URI__.'vitrine/presse/new_covers/thumbs/'.$presse['image'].'"></td><td>'.$presse['date'].'</td><td>
   <a onclick="return confirmDelPresse('.$presse['id'].')" href="'.$currentIndex.'&supprimer_presse=1&id_presse='.$presse['id'].'&conf=1&token='.$this->token.'"><img src="../img/admin/delete.gif" alt="'.$_cacheLang['Delete'].'" title="'.$_cacheLang['Delete'].'" /></a></td></tr>';

 echo'</tfoot></table>
 </fieldset>
 ';

}
public function postProcess()
{
 global $currentIndex;
 if (Tools::getValue('formulaire_envoi_fichier'))
 {
  $date=Tools::getValue('dateop');
  $path_bigs = _PS_ROOT_DIR_."/vitrine/presse/new_covers";
  $path_thumbs = _PS_ROOT_DIR_."/vitrine/presse/new_covers/thumbs";
  $img_thumb_width = 101; //
  $img_big_height = 552; //
  $extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed)
  //List of allowed extensions if extlimit = yes
  //$limitedext = array(".gif",".jpg",".png",".jpeg",".bmp");
  $limitedext = array(".jpg",".jpeg");
  //the image -> variables
  $file_type = $_FILES['thumb_img']['type'];
  $file_name = $_FILES['thumb_img']['name'];
  $file_size = $_FILES['thumb_img']['size'];
  $file_tmp = $_FILES['thumb_img']['tmp_name'];
  /////***********************////////////
  $file_type_big = $_FILES['big_img']['type'];
  $file_name_big = $_FILES['big_img']['name'];
  $file_size_big = $_FILES['big_img']['size'];
  $file_tmp_big = $_FILES['big_img']['tmp_name'];
  ////************************///////////
  //check if you have selected a file.
  if(!is_uploaded_file($file_tmp) OR !is_uploaded_file($file_tmp_big)){
 // echo "Erreur: Selectionner des images!. <br>--<a href=\"$_SERVER[php_SELF]\">Retour</a>";
 $this->_errors[] = Tools::displayError('Selectionner des images!');
 // exit(); //exit the script and don't process the rest of it!
  }
  //check the file's extension
 $ext = strrchr($file_name,'.');
 $ext = strtolower($ext);
 ///////****************************//////////
 $ext_big = strrchr($file_name_big,'.');
 $ext_big = strtolower($ext_big);
 //////*****************************/////////
 //uh-oh! the file extension is not allowed!
 if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
 //echo "Format du tumbnail incorrect.";
 $this->_errors[] = Tools::displayError('Format du tumbnail incorrect.');
 //exit();
 }
 if (($extlimit == "yes") && (!in_array($ext_big,$limitedext))) {
 //echo "Format de la grande image incorrect.";
 $this->_errors[] = Tools::displayError('Format de la grande image incorrect.');
   // exit();
 }
  //so, whats the file's extension?
 $getExt = explode ('.', $file_name);
 $file_ext = $getExt[count($getExt)-1];
 //create a random file name
 $rand_name = md5(time());
 $rand_name= rand(0,999999999);
 //the new width variable
 $ThumbWidth = $img_thumb_width;
 $height_big = $img_big_height;
 //keep image type
 if($file_size){
 if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
   $new_img = imagecreatefromjpeg($file_tmp);
   $new_img_big = imagecreatefromjpeg($file_tmp_big);
  }elseif($file_type == "image/x-png" || $file_type == "image/png"){
   $new_img = imagecreatefrompng($file_tmp);
  }elseif($file_type == "image/gif"){
   $new_img = imagecreatefromgif($file_tmp);
  }
  //list the width and height and keep the height ratio.
  list($width, $height) = getimagesize($file_tmp);
  list($width_big, $height_big) = getimagesize($file_tmp_big);
  //calculate the image ratio
  $imgratio=$width/$height;
  $imgratio_big=$width_big/$height_big;
  if ($imgratio>1 && $imgratio_big){
  $newwidth = $ThumbWidth;
  $newheight = $ThumbWidth/$imgratio;
  $newwidth_big = $height_big;
  $newheight_big = $height_big/$imgratio_big;
  }else{
  $newheight = $ThumbWidth;
  $newwidth = $ThumbWidth*$imgratio;
  $newheight_big = $height_big;
  $newwidth_big = $height_big*$imgratio_big;
  }
  //function for resize image.
  if (function_exists(imagecreatetruecolor)){
  $resized_img = imagecreatetruecolor($newwidth,$newheight);
  $resized_img_big = imagecreatetruecolor($newwidth_big,$newheight_big);
  }else{
  die("Error: Please make sure you have GD library ver 2+");
  }
  //the resizing is going on here!
  imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  imagecopyresized($resized_img_big, $new_img_big, 0, 0, 0, 0, $newwidth_big, $newheight_big, $width_big, $height_big);
  //finally, save the image
  ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext");
  ImageJpeg ($resized_img_big,"$path_bigs/$rand_name.$file_ext");
  ImageDestroy ($resized_img);
  ImageDestroy ($resized_img_big);
  ImageDestroy ($new_img);
  ImageDestroy ($new_img_big);
  $name=$rand_name.'.'.$file_ext;
  //$res=Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'presse (date, image) VALUES ('.$date.','.$name)));
  $res=Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'presse` (`date`,`image`) VALUES (\''.$date.'\',\''.$name.'\')');
  if(!$res)
   $this->_errors[] = Tools::displayError('Erreur d\'ajout.').$name;
   //else

  }


 }
 if (Tools::getValue('supprimer_presse'))
 {
  $id=$_GET['id_presse'];
  $this->DelPresse($id);
 }
}
}
?>

 

qui peut m'aider

Edited by R005 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...