diff --git a/application/modules/admin/controllers/BibController.php b/application/modules/admin/controllers/BibController.php index d2173b32bc79ff9de4e5f831a429f0e2c9c9cd8e..cd8ff8fea975accdd59fc436ed0e249a160203de 100644 --- a/application/modules/admin/controllers/BibController.php +++ b/application/modules/admin/controllers/BibController.php @@ -18,175 +18,157 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -////////////////////////////////////////////////////////////////////////////////////////// -// OPAC3 - Controleur fiche bibliotheque -////////////////////////////////////////////////////////////////////////////////////////// + class Admin_BibController extends Zend_Controller_Action { - private $_pathImg = "./public/admin/images/"; + private $_pathImg = './public/admin/images/'; private $id_zone; - //------------------------------------------------------------------------------------------------------ - // Initialisation du controller - //------------------------------------------------------------------------------------------------------ - function init() { - // Zone et bib du filtre (initialisé dans le plugin DefineUrls) - $this->id_zone=$_SESSION["admin"]["filtre_localisation"]["id_zone"]; - $this->id_bib=$_SESSION["admin"]["filtre_localisation"]["id_bib"]; + public function init() { + // filters are initialized in DefineUrls plugin + $this->id_zone = $_SESSION['admin']['filtre_localisation']['id_zone']; + $this->id_bib = $_SESSION['admin']['filtre_localisation']['id_bib']; - // Variables de vue - $this->view->id_zone=$this->id_zone; - $this->view->id_bib=$this->id_bib; + $this->view->id_zone = $this->id_zone; + $this->view->id_bib = $this->id_bib; } - //------------------------------------------------------------------------------------------------------ - // Liste des bibs - //------------------------------------------------------------------------------------------------------ - function indexAction() - { + + public function indexAction() { $this->view->titre = $this->view->_('Gestion des bibliothèques'); - // Retour accueil ou liste en fonction du role + $user = ZendAfi_Auth::getInstance()->getIdentity(); - if ($user->ROLE_LEVEL < ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) - $this->_redirect('admin/index'); + if ($user->ROLE_LEVEL < ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) { + $this->_redirect('admin/index'); + return; + } - if ($user->ROLE_LEVEL == ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) + if ($user->ROLE_LEVEL == ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) { $this->_redirect(sprintf('admin/bib/edit/id/%d', $user->ID_SITE)); + return; + } - $this->view->bib_array = Class_Bib::getLoader()->findAllByIdZone($this->id_zone); + $this->view->bib_array = Class_Bib::findAllByIdZone($this->id_zone); } - //------------------------------------------------------------------------------------------------------ - // Creation bib - //------------------------------------------------------------------------------------------------------ - function addAction() - { - $this->view->titre = $this->view->_("Ajouter une bibliothèque"); + + public function addAction() { + $this->view->titre = $this->view->_('Ajouter une bibliothèque'); - if ($this->_request->isPost()) - { - $filter = new Zend_Filter_StripTags(); + if ($this->_request->isPost()) { + $filter = new Zend_Filter_StripTags(); - $libelle = trim($filter->filter($this->_request->getPost('libelle'))); - $responsable = trim($filter->filter($this->_request->getPost('responsable'))); - $adresse = trim($filter->filter($this->_request->getPost('adresse'))); - $cp = trim($filter->filter($this->_request->getPost('cp'))); - $ville = trim($filter->filter($this->_request->getPost('ville'))); - $tel = trim($filter->filter($this->_request->getPost('tel'))); - $mail = trim($filter->filter($this->_request->getPost('mail'))); - $zone = (int)trim($filter->filter($this->_request->getPost('zone'))); - $carto = trim($filter->filter($this->_request->getPost('carto'))); - $inscription = trim($filter->filter($this->_request->getPost('inscription'))); - $pret = trim($filter->filter($this->_request->getPost('pret'))); - $fond = trim($filter->filter($this->_request->getPost('fond'))); - $procur = trim($filter->filter($this->_request->getPost('procur'))); - $annexe = trim($filter->filter($this->_request->getPost('annexe'))); - $statut = trim($filter->filter($this->_request->getPost('statut'))); - $url = trim($filter->filter($this->_request->getPost('url'))); - $horaire = trim($filter->filter($this->_request->getPost('horaire'))); - $photo = trim($filter->filter($this->_request->getPost('photo'))); + $libelle = trim($filter->filter($this->_request->getPost('libelle'))); + $responsable = trim($filter->filter($this->_request->getPost('responsable'))); + $adresse = trim($filter->filter($this->_request->getPost('adresse'))); + $cp = trim($filter->filter($this->_request->getPost('cp'))); + $ville = trim($filter->filter($this->_request->getPost('ville'))); + $tel = trim($filter->filter($this->_request->getPost('tel'))); + $mail = trim($filter->filter($this->_request->getPost('mail'))); + $zone = (int)trim($filter->filter($this->_request->getPost('zone'))); + $carto = trim($filter->filter($this->_request->getPost('carto'))); + $inscription = trim($filter->filter($this->_request->getPost('inscription'))); + $pret = trim($filter->filter($this->_request->getPost('pret'))); + $fond = trim($filter->filter($this->_request->getPost('fond'))); + $procur = trim($filter->filter($this->_request->getPost('procur'))); + $annexe = trim($filter->filter($this->_request->getPost('annexe'))); + $statut = trim($filter->filter($this->_request->getPost('statut'))); + $url = trim($filter->filter($this->_request->getPost('url'))); + $horaire = trim($filter->filter($this->_request->getPost('horaire'))); + $photo = trim($filter->filter($this->_request->getPost('photo'))); - $data = array( - 'ID_SITE' => '', - 'LIBELLE' => $libelle, - 'RESPONSABLE' => $responsable, - 'ADRESSE' => $adresse, - 'CP' => $cp, - 'VILLE' => $ville, - 'TELEPHONE' => $tel, - 'MAIL' => $mail, - 'ID_ZONE' => $zone, - 'LIEN_CARTO' => $carto, - 'VISIBILITE' => $statut, - 'URL_WEB' => $url, - 'INSCRIPTION' => $inscription, - 'PRET' => $pret, - 'FOND' => $fond, - 'PROCURE' => $procur, - 'ANNEXE' => $annexe, - 'PHOTO' => $photo, - 'HORAIRE' => $horaire, - 'GOOGLE_MAP' => '', - 'INTERDIRE_RESA' => $this->_request->getPost('interdire_resa') - ); + $data = ['ID_SITE' => '', + 'LIBELLE' => $libelle, + 'RESPONSABLE' => $responsable, + 'ADRESSE' => $adresse, + 'CP' => $cp, + 'VILLE' => $ville, + 'TELEPHONE' => $tel, + 'MAIL' => $mail, + 'ID_ZONE' => $zone, + 'LIEN_CARTO' => $carto, + 'VISIBILITE' => $statut, + 'URL_WEB' => $url, + 'INSCRIPTION' => $inscription, + 'PRET' => $pret, + 'FOND' => $fond, + 'PROCURE' => $procur, + 'ANNEXE' => $annexe, + 'PHOTO' => $photo, + 'HORAIRE' => $horaire, + 'GOOGLE_MAP' => '', + 'INTERDIRE_RESA' => $this->_request->getPost('interdire_resa')]; - $bibClass = new Class_Bib(); - $errorMessage = $bibClass->addBib($data); - if ($errorMessage == '') - { - // Modif adresse photo - if($photo) - { - $id_bib=fetchOne("select max(ID_SITE) from BIB_C_SITE"); - $img_temp=getcwd()."/userfiles/photobib/photoBib0.jpg"; - $img="/userfiles/photobib/photoBib".$id_bib.".jpg"; - $req="update BIB_C_SITE set PHOTO='$img' where ID_SITE=$id_bib"; - sqlExecute($req); - rename($img_temp,getcwd().$img); - } - $this->_redirect('admin/bib?z='.$this->id_zone); - } - else - { - $this->view->message = $errorMessage; - $this->view->ID_ZONE = $this->id_zone; - $this->view->bib = new stdClass(); - $this->view->bib->LIBELLE = $libelle; - $this->view->bib->RESPONSABLE = $responsable; - $this->view->bib->ADRESSE = $adresse; - $this->view->bib->CP = $cp; - $this->view->bib->VILLE = $ville; - $this->view->bib->TELEPHONE = $tel; - $this->view->bib->MAIL = $mail; - $this->view->bib->LIEN_CARTO = $carto; - $this->view->bib->INSCRIPTION = $inscription; - $this->view->bib->PRET = $pret; - $this->view->bib->FOND = $fond; - $this->view->bib->PROCURE = $procur; - $this->view->bib->ANNEXE = $annexe; - $this->view->bib->HORAIRE = $horaire; - $this->view->bib->PHOTO = $photo; - $this->view->bib->URL_WEB = $url; - $this->view->bib->ID_SITE = null; - } - } - else - { - $this->view->ID_ZONE = $this->id_zone; - // supprime la photo temporaire - $adresse_img=getcwd()."/userfiles/photobib/photoBib0.jpg"; - if(file_exists($adresse_img)) unlink($adresse_img); + $bibClass = new Class_Bib(); + $errorMessage = $bibClass->addBib($data); + if ($errorMessage == '') { + if($photo) { + $id_bib = fetchOne("select max(ID_SITE) from BIB_C_SITE"); + $img_temp = getcwd()."/userfiles/photobib/photoBib0.jpg"; + $img = "/userfiles/photobib/photoBib".$id_bib.".jpg"; + $req = "update BIB_C_SITE set PHOTO='$img' where ID_SITE=$id_bib"; + sqlExecute($req); + rename($img_temp,getcwd().$img); + } + $this->_redirect('admin/bib?z='.$this->id_zone); + return; } - // combo des zones + + + $this->view->message = $errorMessage; + $this->view->ID_ZONE = $this->id_zone; + $this->view->bib = new stdClass(); + $this->view->bib->LIBELLE = $libelle; + $this->view->bib->RESPONSABLE = $responsable; + $this->view->bib->ADRESSE = $adresse; + $this->view->bib->CP = $cp; + $this->view->bib->VILLE = $ville; + $this->view->bib->TELEPHONE = $tel; + $this->view->bib->MAIL = $mail; + $this->view->bib->LIEN_CARTO = $carto; + $this->view->bib->INSCRIPTION = $inscription; + $this->view->bib->PRET = $pret; + $this->view->bib->FOND = $fond; + $this->view->bib->PROCURE = $procur; + $this->view->bib->ANNEXE = $annexe; + $this->view->bib->HORAIRE = $horaire; + $this->view->bib->PHOTO = $photo; + $this->view->bib->URL_WEB = $url; + $this->view->bib->ID_SITE = null; + + } else { + $this->view->ID_ZONE = $this->id_zone; + $adresse_img = getcwd()."/userfiles/photobib/photoBib0.jpg"; + if(file_exists($adresse_img)) + unlink($adresse_img); + } + $cls_zone = new Class_Zone(); $this->view->combo_zone=$cls_zone->getComboZone($zone); - $this->view->action = 'add'; } - //------------------------------------------------------------------------------------------------------ - // Modif bib - //------------------------------------------------------------------------------------------------------ - function editAction() { + + public function editAction() { $user = ZendAfi_Auth::getInstance()->getIdentity(); - if ($user->ROLE_LEVEL < ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) + if ($user->ROLE_LEVEL < ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) { $this->_redirect('admin/index'); + return; + } - if ($this->_request->isPost()) - $id = (int)$this->_request->getPost('id_bib'); - else - $id = (int)$this->_request->getParam('id', 0); - + $id = (int)($this->_request->isPost()) ? + $this->_request->getPost('id_bib') : + $this->_request->getParam('id', 0); if ($user->ROLE_LEVEL == ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB and $user->ID_SITE != $id) { $this->_redirect('admin/index'); + return; } $bibClass = new Class_Bib(); - // Si c envoyé if ($this->_request->isPost()) { $filter = new Zend_Filter_StripTags(); @@ -210,56 +192,57 @@ class Admin_BibController extends Zend_Controller_Action { $photo = trim($filter->filter($this->_request->getPost('photo'))); if ($id !== false ) { - $data = array( - 'ID_SITE' => $id, - 'LIBELLE' => $libelle, - 'RESPONSABLE' => $responsable, - 'ADRESSE' => $adresse, - 'CP' => $cp, - 'VILLE' => $ville, - 'TELEPHONE' => $tel, - 'MAIL' => $mail, - 'ID_ZONE' => $zone, - 'LIEN_CARTO' => $carto, - 'VISIBILITE' => $statut, - 'URL_WEB' => $url, - 'INSCRIPTION' => $inscription, - 'PRET' => $pret, - 'FOND' => $fond, - 'PROCURE' => $procur, - 'ANNEXE' => $annexe, - 'PHOTO' => $photo, - 'HORAIRE' => $horaire, - 'INTERDIRE_RESA' => $this->_request->getPost('interdire_resa') - ); + $data = ['ID_SITE' => $id, + 'LIBELLE' => $libelle, + 'RESPONSABLE' => $responsable, + 'ADRESSE' => $adresse, + 'CP' => $cp, + 'VILLE' => $ville, + 'TELEPHONE' => $tel, + 'MAIL' => $mail, + 'ID_ZONE' => $zone, + 'LIEN_CARTO' => $carto, + 'VISIBILITE' => $statut, + 'URL_WEB' => $url, + 'INSCRIPTION' => $inscription, + 'PRET' => $pret, + 'FOND' => $fond, + 'PROCURE' => $procur, + 'ANNEXE' => $annexe, + 'PHOTO' => $photo, + 'HORAIRE' => $horaire, + 'INTERDIRE_RESA' => $this->_request->getPost('interdire_resa')]; $errorMessage = $bibClass->editBib($data, $id); - // Redirection en fonction du role - $redirect="admin"; + $redirect = 'admin'; $user = ZendAfi_Auth::getInstance()->getIdentity(); - if ($user->ROLE_LEVEL > ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL) $redirect.="/bib?z=".$this->id_zone; + if ($user->ROLE_LEVEL > ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL) + $redirect .= "/bib?z=" . $this->id_zone; - if ($errorMessage == '') + if ($errorMessage == '') { $this->_redirect($redirect); - else { - $bib = $bibClass->getBibById($id); - if (is_string($bib) ) $this->_redirect('admin/error/database'); - else { - $this->view->bib = $bib; - $this->view->message = $errorMessage; - } + return; + } + + $bib = $bibClass->getBibById($id); + if (is_string($bib)) { + $this->_redirect('admin/error/database'); + return; } + + $this->view->bib = $bib; + $this->view->message = $errorMessage; } } else { - if (!$bib = Class_Bib::getLoader()->find($id)) { + if (!$bib = Class_Bib::find($id)) { $this->_redirect('admin/bib/index?z='.$this->id_zone); return; } } - // combo des zones + $cls_zone = new Class_Zone(); - $this->view->combo_zone=$cls_zone->getComboZone($bib->ID_ZONE); + $this->view->combo_zone = $cls_zone->getComboZone($bib->ID_ZONE); $this->view->titre = $this->view->_("Modifier la bibliothèque: %s", $bib->LIBELLE); $this->view->action = 'edit'; @@ -267,113 +250,107 @@ class Admin_BibController extends Zend_Controller_Action { $this->view->id = $id; } - //------------------------------------------------------------------------------------------------------ - // Suppression bib - //------------------------------------------------------------------------------------------------------ - function deleteAction() { + + public function deleteAction() { $bib = Class_Bib::find((int)$this->_request->getParam('id')); $this->view->titre = $this->view->_('Supprimer la bibliothèque: %s', $bib->getLibelle()); $this->view->bib = $bib; } - function forceDeleteAction() { + public function forceDeleteAction() { $bib = Class_Bib::find((int)$this->_request->getParam('id')); $bib->delete(); $this->_helper->notify('La bibliothèque "'.$bib->getLibelle().'" a été supprimée'); $this->_redirect('admin/bib/index'); } - //------------------------------------------------------------------------------------------------------ - // Photo bib (affichage et upload) - //------------------------------------------------------------------------------------------------------ - function photoAction() - { + + public function photoAction() { $viewRenderer = $this->getHelper('ViewRenderer'); $viewRenderer->setNoRender(); // Parametres et adresse du fichier $id_bib = (int)$this->_request->getParam('id'); - $img="/userfiles/photobib/photoBib".$id_bib.".jpg"; - $url_img=$this->view->url(['module'=>'admin', - 'controller'=>'bib', - 'action'=>'getimage', - 'id'=>$id_bib]); - $adresse_img=getcwd().$img; - if(! file_exists($adresse_img)) $url_img=BASE_URL."/userfiles/photobib/photoVide.jpg"; - - // Debut html - $html='<body style="background-color:#f0f0f0;overflow:hidden">'; - $html.='<link rel="stylesheet" type="text/css" media="screen" href="'.URL_ADMIN_CSS.'global.css" />'; - $html.='<div>'; + $img = "/userfiles/photobib/photoBib".$id_bib.".jpg"; + $url_img = $this->view->url(['module'=>'admin', + 'controller'=>'bib', + 'action'=>'getimage', + 'id'=>$id_bib]); + $adresse_img = getcwd().$img; + if (!file_exists($adresse_img)) + $url_img = BASE_URL."/userfiles/photobib/photoVide.jpg"; + + $html = '<body style="background-color:#f0f0f0;overflow:hidden">'; + $html .= '<link rel="stylesheet" type="text/css" media="screen" href="'.URL_ADMIN_CSS.'global.css" />'; + $html .= '<div>'; - // Traitement de la photo - if($_FILES["photo"]) - { - $fic = $_FILES["photo"]; - $html.= $this->view->_("Fichier photo : %s", $fic["name"].BR); - if($fic["error"] > 0) - { - if(!$fic["name"]) $erreur=$this->view->_("Vous devez sélectionner une photo en cliquant sur le bouton : parcourir"); - elseif(!$fic["size"]) $erreur=$this->view->_("Le fichier que vous avez sélectionné est vide."); - else $erreur=$this->view->_('Erreur au téléchargement du fichier : L\'image que vous essayez de télécharger est trop volumineuse ou inaccessible.'); - } - else - { - // Controles - $ext=strToLower(strRight($fic["type"],3)); - $taille=(int)($fic["size"]/1024); - if($ext !="jpg" and $ext != "peg") $erreur=$this->view->_("La photo que vous avez sélectionnée doit être de type : 'image/jpg' et pas de type : %s", $fic["type"]); - elseif($taille > 100 ) $erreur=$this->view->_("La photo que vous avez sélectionnée est trop volumiseuse : %d ko", $taille); - else - { - if(move_uploaded_file($fic['tmp_name'],$adresse_img)) - { - $html.="<script>document.location.replace('".BASE_URL."/admin/bib/photo?id=".$id_bib."&upload=1')</script>"; - } - else $erreur=$this->view->_("Erreur au transfert du fichier vers userfiles"); - } - } - if($erreur) - { - $html.=BR.'<span>'.$erreur.'</span>'; - $html.=BR.BR.'<center><input type="button" class="bouton" value="'.$this->view->_("Retour").'" onclick="document.location.replace(\''.BASE_URL.'/admin/bib/photo?id='.$id_bib.'\')">'; + + if ($_FILES["photo"]) { + $fic = $_FILES["photo"]; + $html .= $this->view->_("Fichier photo : %s", $fic["name"] . BR); + if($fic["error"] > 0) { + if(!$fic["name"]) { + $erreur = $this->view->_("Vous devez sélectionner une photo en cliquant sur le bouton : parcourir"); + } elseif(!$fic["size"]) { + $erreur = $this->view->_("Le fichier que vous avez sélectionné est vide."); + } else { + $erreur = $this->view->_('Erreur au téléchargement du fichier : L\'image que vous essayez de télécharger est trop volumineuse ou inaccessible.'); + } + + } else { + $ext=strToLower(strRight($fic["type"],3)); + $taille=(int)($fic["size"]/1024); + if ($ext !="jpg" and $ext != "peg") { + $erreur = $this->view->_("La photo que vous avez sélectionnée doit être de type : 'image/jpg' et pas de type : %s", $fic["type"]); + } elseif($taille > 100 ) { + $erreur = $this->view->_("La photo que vous avez sélectionnée est trop volumiseuse : %d ko", $taille); + } else { + if(move_uploaded_file($fic['tmp_name'], $adresse_img)) { + $html .= "<script>document.location.replace('".BASE_URL."/admin/bib/photo?id=".$id_bib."&upload=1')</script>"; + } else { + $erreur = $this->view->_("Erreur au transfert du fichier vers userfiles"); } + } } - else - { - if($_REQUEST["upload"]==1) - { - $html.='<script>window.top.document.getElementById("photo").value="'.$img.'";</script>'; - } - $html.='<form name="form" action="'.BASE_URL.'/admin/bib/photo?id='.$id_bib.'" enctype="multipart/form-data" method="post">'; - $html.='<table><tr>'; - $html.='<td width="190px"><img src="'.$url_img.'" width="180px" height="140px"></td>'; - $html.='<td style=padding-left:10px"><span style="font-size:12px">'.$this->view->_('NB : l\'image doit être de type ".jpg", avoir une taille inférieure à 100 ko et des dimensions se rapprochant de 180 / 140 pixels').'</span><br/><br/>'; - $html.='<center><input type="file" name="photo" size="40" enctype="multipart/form-data">'; - $html.='<br/><br/><input type="submit" class="bouton" value="'.$this->view->_('Envoyer la photo sur le serveur').'"></td>'; - $html.='</tr></table></form>'; + + if($erreur) { + $html .= BR.'<span>'.$erreur.'</span>'; + $html .= BR.BR.'<center><input type="button" class="bouton" value="'.$this->view->_("Retour").'" onclick="document.location.replace(\''.BASE_URL.'/admin/bib/photo?id='.$id_bib.'\')">'; } + + } else { + if ($_REQUEST["upload"]==1) { + $html.='<script>window.top.document.getElementById("photo").value="'.$img.'";</script>'; + } + + $html .= '<form name="form" action="'.BASE_URL.'/admin/bib/photo?id='.$id_bib.'" enctype="multipart/form-data" method="post">'; + $html .= '<table><tr>'; + $html .= '<td width="190px"><img src="'.$url_img.'" width="180px" height="140px"></td>'; + $html .= '<td style=padding-left:10px"><span style="font-size:12px">'.$this->view->_('NB : l\'image doit être de type ".jpg", avoir une taille inférieure à 100 ko et des dimensions se rapprochant de 180 / 140 pixels').'</span><br/><br/>'; + $html .= '<center><input type="file" name="photo" size="40" enctype="multipart/form-data">'; + $html .= '<br/><br/><input type="submit" class="bouton" value="'.$this->view->_('Envoyer la photo sur le serveur').'"></td>'; + $html .= '</tr></table></form>'; + } - $html.='</div>'; - $html.='<script>document.body.setAttribute("bgColor ","#f0f0f0"))</script>'; + $html .= '</div>'; + $html .= '<script>document.body.setAttribute("bgColor ","#f0f0f0"))</script>'; + $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); $this->getResponse()->setHeader('pragma', 'no-cache'); $this->getResponse()->setBody($html); } - //------------------------------------------------------------------------------------------------------ - // Photo bib (envoi contenu image en flux) - //------------------------------------------------------------------------------------------------------ - function getimageAction() - { + + public function getimageAction() { $id_bib = (int)$this->_request->getParam('id'); - $img="/userfiles/photobib/photoBib".$id_bib.".jpg"; + $img = "/userfiles/photobib/photoBib".$id_bib.".jpg"; $adresse_img=getcwd().$img; - if(! file_exists($adresse_img)) $adresse_img=getcwd()."/userfiles/photobib/photoVide.jpg"; + if (!file_exists($adresse_img)) + $adresse_img = getcwd()."/userfiles/photobib/photoVide.jpg"; - $handle=fopen($adresse_img,"rb"); - $data=fread ($handle, filesize($adresse_img)); + $handle = fopen($adresse_img,"rb"); + $data = fread($handle, filesize($adresse_img)); fclose($handle); header("Content-type: image/jpg"); @@ -382,76 +359,64 @@ class Admin_BibController extends Zend_Controller_Action { exit; } - //------------------------------------------------------------------------------------------------------ - // Localisations : liste - //------------------------------------------------------------------------------------------------------ - function localisationsAction() - { + + public function localisationsAction() { $cls_loc = new Class_Localisation(); $id_bib = (int)$this->_request->getParam('id_bib'); - $this->view->id_bib=$id_bib; - $this->view->nom_bib=fetchOne("select LIBELLE from bib_c_site where ID_SITE=$id_bib"); - $this->view->localisations=$cls_loc->getLocalisations($id_bib); - $this->view->titre = $this->view->_("Localisations de la bibliothèque: %s", $this->view->nom_bib); + $this->view->id_bib = $id_bib; + $this->view->nom_bib = fetchOne("select LIBELLE from bib_c_site where ID_SITE=$id_bib"); + $this->view->localisations = $cls_loc->getLocalisations($id_bib); + $this->view->titre = $this->view->_("Localisations de la bibliothèque: %s", + $this->view->nom_bib); } - //------------------------------------------------------------------------------------------------------ - // Localisations : creation / modif - //------------------------------------------------------------------------------------------------------ - function localisationsmajAction() - { + + public function localisationsmajAction() { $cls_loc = new Class_Localisation(); $id_localisation=(int)$this->_request->getParam('id_localisation'); $id_bib = (int)$this->_request->getParam('id_bib'); - // Validation - if ($this->_request->isPost()) - { - $data=ZendAfi_Filters_Post::filterStatic($this->_request->getPost()); - if(!$data["LIBELLE"])$erreurs[]=$this->view->_("le libellé est obligatoire."); - if($erreurs) - { - $this->view->erreurs=$erreurs; - $id_localisation=0; - $enreg=$data; - } - // Ecriture - else - { - $data["ID_BIB"]=$id_bib; - if(!$data["ANIMATION"]) $data["ANIMATION"]="etoile.gif"; - Class_AdminVar::set("animation",$data["ANIMATION"]); - $cls_loc->ecrireLocalisation($id_localisation,$data); - $this->_redirect('admin/bib/localisations?id_bib='.$id_bib); - } + if ($this->_request->isPost()) { + $data = ZendAfi_Filters_Post::filterStatic($this->_request->getPost()); + if(!$data["LIBELLE"]) + $erreurs[] = $this->view->_("le libellé est obligatoire."); + + if($erreurs) { + $this->view->erreurs=$erreurs; + $id_localisation=0; + $enreg=$data; + } else { + $data["ID_BIB"]=$id_bib; + if(!$data["ANIMATION"]) + $data["ANIMATION"]="etoile.gif"; + Class_AdminVar::set("animation", $data["ANIMATION"]); + $cls_loc->ecrireLocalisation($id_localisation,$data); + $this->_redirect('admin/bib/localisations?id_bib='.$id_bib); + return; } - // Entree dans le formulaire - else - { - if($this->_request->getParam('creation')==1) - { - $id_localisation=0; - $enreg["LIBELLE"]=$this->view->_("** nouvelle localisation **"); - $enreg["ANIMATION"]=getVar("animation"); - } - else - { - $id_localisation = (int)$this->_request->getParam('id_localisation'); - $enreg=$cls_loc->getLocalisations($id_bib,$id_localisation); - } + } else { + if($this->_request->getParam('creation')==1) { + $id_localisation=0; + $enreg["LIBELLE"]=$this->view->_("** nouvelle localisation **"); + $enreg["ANIMATION"]=getVar("animation"); + } else { + $id_localisation = (int)$this->_request->getParam('id_localisation'); + $enreg=$cls_loc->getLocalisations($id_bib,$id_localisation); } + } // Plans $table_plans[0]="aucun"; $plans=$cls_loc->getPlans($id_bib); - if($plans) - { - foreach($plans as $plan) $table_plans[$plan["ID_PLAN"]]=$plan["LIBELLE"]; - } + if ($plans) { + foreach($plans as $plan) + $table_plans[$plan["ID_PLAN"]] = $plan["LIBELLE"]; + } // Variables de vue - if(!$enreg["ANIMATION"]) $enreg["ANIMATION"]="etoile.gif"; + if(!$enreg["ANIMATION"]) + $enreg["ANIMATION"]="etoile.gif"; $this->view->plans=$table_plans; $this->view->id_bib=$id_bib; $this->view->nom_bib=fetchOne("select LIBELLE from bib_c_site where ID_SITE=$id_bib"); @@ -460,11 +425,8 @@ class Admin_BibController extends Zend_Controller_Action { $this->view->titre = $this->view->_("Mise à jour de la localisation"); } - //------------------------------------------------------------------------------------------------------ - // Localisations : suppression - //------------------------------------------------------------------------------------------------------ - function localisationsdeleteAction() - { + + public function localisationsdeleteAction() { $cls_loc = new Class_Localisation(); $id_localisation=(int)$this->_request->getParam('id_localisation'); $id_bib = (int)$this->_request->getParam('id_bib'); @@ -472,138 +434,116 @@ class Admin_BibController extends Zend_Controller_Action { $this->_redirect('admin/bib/localisations?id_bib='.$id_bib); } - //------------------------------------------------------------------------------------------------------ - // Plans : rend la balise image du plan (appel ajax) - //------------------------------------------------------------------------------------------------------ - function ajaximageplanAction() - { - $cls_loc = new Class_Localisation(); - $id_plan=$this->_request->getParam('id_plan'); - $image=$cls_loc->getImagePlan($id_plan); - if(!$image) $html='ERREUR'; - else - { - $html='<a id="ref_plan" href="'.$image["url"].'" rel="lightbox" title="">'; - $html.='<img id="img_plan" src="'.$image["url"].'">'; - $html.='</a>'; - } - // Renvoyer la reponse + public function ajaximageplanAction() { $viewRenderer = $this->getHelper('ViewRenderer'); $viewRenderer->setNoRender(); - print($html); + + $cls_loc = new Class_Localisation(); + $id_plan = $this->_request->getParam('id_plan'); + $image = $cls_loc->getImagePlan($id_plan); + if (!$image) { + print('ERREUR'); + exit; + } + + print('<a id="ref_plan" href="'.$image["url"].'" rel="lightbox" title="">' + . '<img id="img_plan" src="'.$image["url"].'">' + . '</a>'); exit; } - //------------------------------------------------------------------------------------------------------ - // Plans : liste - //------------------------------------------------------------------------------------------------------ - function plansAction() - { + + public function plansAction() { $cls_loc = new Class_Localisation(); $id_bib = (int)$this->_request->getParam('id_bib'); - $this->view->id_bib=$id_bib; - $this->view->nom_bib=fetchOne("select LIBELLE from bib_c_site where ID_SITE=$id_bib"); - $this->view->plans=$cls_loc->getPlans($id_bib); + $this->view->id_bib = $id_bib; + $this->view->nom_bib = fetchOne("select LIBELLE from bib_c_site where ID_SITE=$id_bib"); + $this->view->plans = $cls_loc->getPlans($id_bib); $this->view->titre = $this->view->_('Plans de la bibliothèque: %s', $this->view->nom_bib); } - //------------------------------------------------------------------------------------------------------ - // Plans : creation / modif - //------------------------------------------------------------------------------------------------------ - function plansmajAction() - { + + public function plansmajAction() { $cls_loc = new Class_Localisation(); $id_plan=(int)$this->_request->getParam('id_plan'); $id_bib = (int)$this->_request->getParam('id_bib'); - // Validation - if ($this->_request->isPost()) - { - $data=ZendAfi_Filters_Post::filterStatic($this->_request->getPost()); - if(!$data["LIBELLE"])$erreurs[]=$this->view->_("le libellé est obligatoire."); - if(!$data["IMAGE"]) $erreurs[]=$this->view->_("L'image du plan est obligatoire."); - if($erreurs) - { - $this->view->erreurs=$erreurs; - $id_plan=0; - $enreg=$data; - } - // Ecriture - else - { - $data["ID_BIB"]=$id_bib; - $cls_loc->ecrirePlan($id_plan,$data); - $this->_redirect('admin/bib/plans?id_bib='.$id_bib); - } + if ($this->_request->isPost()) { + $data = ZendAfi_Filters_Post::filterStatic($this->_request->getPost()); + if(!$data["LIBELLE"]) + $erreurs[] = $this->view->_("le libellé est obligatoire."); + if(!$data["IMAGE"]) + $erreurs[]=$this->view->_("L'image du plan est obligatoire."); + + if($erreurs) { + $this->view->erreurs=$erreurs; + $id_plan=0; + $enreg=$data; + } else { + $data["ID_BIB"]=$id_bib; + $cls_loc->ecrirePlan($id_plan,$data); + $this->_redirect('admin/bib/plans?id_bib='.$id_bib); } - // Entree dans le formulaire - else { + } else { $add_action = ($this->_request->getParam('creation')==1); if($add_action) { $id_plan=0; $enreg["LIBELLE"]=$this->view->_("** nouveau plan **"); - } - else { + + } else { $id_plan = (int)$this->_request->getParam('id_plan'); $enreg=$cls_loc->getPlans($id_bib,$id_plan); } + } $nom_bib=fetchOne("select LIBELLE from bib_c_site where ID_SITE=$id_bib"); - if ($add_action) - $this->view->titre = $this->view->_('Ajouter un plan de la bibliothèque: %s', $nom_bib); - else - $this->view->titre = $this->view->_('Modifier un plan de la bibliothèque: %s', $nom_bib); + $this->view->titre = ($add_action) ? + $this->view->_('Ajouter un plan de la bibliothèque: %s', $nom_bib) : + $this->view->_('Modifier un plan de la bibliothèque: %s', $nom_bib); - // Variables de vue - $this->view->id_bib=$id_bib; - $this->view->id_plan=$id_plan; - $this->view->plan=$enreg; + $this->view->id_bib = $id_bib; + $this->view->id_plan = $id_plan; + $this->view->plan = $enreg; } - //------------------------------------------------------------------------------------------------------ - // Plans : suppression - //------------------------------------------------------------------------------------------------------ - function plansdeleteAction() - { + + public function plansdeleteAction() { $cls_loc = new Class_Localisation(); - $id_plan=(int)$this->_request->getParam('id_plan'); + $id_plan = (int)$this->_request->getParam('id_plan'); $id_bib = (int)$this->_request->getParam('id_bib'); $cls_loc->deletePlan($id_plan); - $this->_redirect('admin/bib/plans?id_bib='.$id_bib); + $this->_redirect('admin/bib/plans?id_bib=' . $id_bib); } - function articlesAction() { + public function articlesAction() { $this->_helper->viewRenderer->setNoRender(); $include_items = ! (bool)$this->_getParam('categories_only', false); $id_bib = (int)$this->_getParam('id_bib', 0); - if ($id_bib) - $bibs = array(Class_Bib::getLoader()->find($id_bib)); - else { - $bibs = Class_Bib::getLoader()->findAllByWithPortail(array('order' => 'libelle')); - } + $bibs = ($id_bib) ? + [Class_Bib::find($id_bib)] : + Class_Bib::findAllByWithPortail(['order' => 'libelle']); - $jsons = array(); + $jsons = []; foreach($bibs as $bib) - $jsons []= $bib->articlesToJSON($include_items); + $jsons[] = $bib->articlesToJSON($include_items); $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); $this->getResponse()->setBody('['.implode(',', $jsons).']'); } - /* - * Renvoie tous les items / catégories au format JSON. - * Utilisé pour l'objet jQuery TreeSelect + /** + * used by TreeSelect * type = cms | sito | rss * id_bib : l'id de la bib, 0 signifie toutes les bibliothèques * categories_only: si == 1, les items (articles, flux ou sites) ne seront pas chargées. */ - function allitemsAction() { + public function allitemsAction() { $this->_helper->viewRenderer->setNoRender(); $id_bib = (int)$this->_request->getParam('id_bib', 0); @@ -613,9 +553,9 @@ class Admin_BibController extends Zend_Controller_Action { $class_bib = new Class_Bib(); $cats_by_bib = $class_bib->buildBibTree($id_bib, $type, $do_load_items); - $jsons = array(); + $jsons = []; foreach($cats_by_bib as $bib) - $jsons []= $bib->toJSON(); + $jsons[] = $bib->toJSON(); $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); $this->getResponse()->setBody('['.implode(',', $jsons).']');