/**
  * récupèration d'un profil de connection à une base de données.
  * @access private
  * @param string  $named  nom du profil de connection
  * @return    CopixLdapProfil   profil de connection
  */
 private function _getProfil($named)
 {
     $pluginLdap = CopixPluginRegistry::get('CopixLdap');
     if (isset($pluginLdap->config->profils[$named])) {
         return $pluginLdap->config->profils[$named];
     }
     throw new CopixException(_i18n('copix:ldap.error.unknowProfil', $named));
 }
 /**
  * Envoie un minimail
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2005/10/18
  * @param string title Titre du minimail
  * @param string message Corps du minimail
  * @param integer from_id Id utilisateur de l'exp�diteur
  * @param array destin Id tableau avec les destinataires (cl� = id user)
  * @return mixed Id du message cr�� ou NULL si erreur
  */
 public function sendMinimail($title, $message, $from_id, $destin, $format)
 {
     $res = NULL;
     $DAOminimail_from = _dao("minimail|minimail_from");
     $DAOminimail_to = _dao("minimail|minimail_to");
     $newMp = _record("minimail|minimail_from");
     $newMp->title = $title;
     $newMp->message = $message;
     $newMp->format = $format;
     $newMp->date_send = date("Y-m-d H:i:s");
     $newMp->from_id = $from_id;
     $newMp->is_deleted = 0;
     $DAOminimail_from->insert($newMp);
     if ($newMp->id !== NULL) {
         //print_r($newMp);
         // On parcourt chaque destinataire
         while (list($to_id, ) = each($destin)) {
             // print_r("to_id=$to_id / to_login=$to_login");
             $newDest = _record("minimail|minimail_to");
             $newDest->id_message = $newMp->id;
             $newDest->to_id = $to_id;
             $newDest->date_read = 0;
             $newDest->is_read = 0;
             $newDest->is_replied = 0;
             $newDest->is_deleted = 0;
             $DAOminimail_to->insert($newDest);
             // ======= Alerte mail ===============
             // On vérifie que l'envoi de mails est activé, qu'un serveur SMTP est configuré, que le destinataire a coché l'option "etre prêvenu par mail" et qu'il a renseigné un mail
             if ($newDest->id2 && CopixConfig::get('|mailEnabled') == 1 && CopixConfig::get('|mailSmtpHost')) {
                 $prefs = Prefs::getPrefs($to_id);
                 if (isset($prefs['prefs']['alerte_mail_email']) && isset($prefs['minimail']['alerte_minimail']) && $prefs['prefs']['alerte_mail_email'] && $prefs['minimail']['alerte_minimail'] == 1) {
                     $userInfoFrom = Kernel::getUserInfo("ID", $from_id);
                     //print_r($userInfoFrom);
                     $to = $prefs['prefs']['alerte_mail_email'];
                     $auteur = utf8_decode($userInfoFrom['prenom'] . ' ' . $userInfoFrom['nom'] . ' (' . $userInfoFrom['login'] . ')');
                     $subject = CopixI18N::get('minimail|minimail.mail.alert.subject', array($auteur));
                     $message = str_replace('<br />', "\n", CopixI18N::get('minimail|minimail.mail.alert.body', array($auteur, CopixUrl::get('minimail||getMessage', array('id' => $newMp->id)), CopixUrl::get())));
                     $from = CopixConfig::get('default|mailFrom');
                     $fromName = CopixConfig::get('default|mailFromName');
                     $cc = $cci = '';
                     $monMail = new CopixTextEMail($to, $cc, $cci, $subject, $message);
                     $send = $monMail->send($from, $fromName);
                 }
             }
             // ======= Fin alerte mail ===============
         }
         $res = $newMp->id;
         if ($res) {
             $plugStats = CopixPluginRegistry::get("stats|stats");
             $plugStats->setParams(array('module' => 'minimail', 'action' => 'sendMinimail', 'objet_a' => $res));
         }
     }
     return $res;
 }
 public function _createContent(&$toReturn)
 {
     $tpl = new CopixTpl();
     $blog = $this->getParam('blog', '');
     $comment = $this->getParam('comment', NULL);
     //on récupère l'ensemble des articles du blog
     $dao = _dao('blog|blogarticle');
     //$article = $dao->getArticleByUrl($blog->id_blog, $this->getParam('article', ''));
     list($id_bact, ) = explode("-", $this->getParam('article', ''));
     $article = $dao->getArticleById($blog->id_blog, $id_bact);
     if (!$article) {
         $toReturn = '{/}' . $tpl->fetch('showarticle.tpl');
         return true;
     }
     //encodage des URL des catégories pour caractères spéciaux
     if (is_array($article->categories)) {
         foreach ($article->categories as $key => $categorie) {
             $article->categories[$key]->url_bacg = urlencode($categorie->url_bacg);
         }
     }
     $tpl->assign('article', $article);
     // Recherche de tous les commentaires associés à cet article
     $commentDAO = _dao('blog|blogarticlecomment');
     $res = $commentDAO->findCommentOrderBy($article->id_bact, 1);
     $listComment = array();
     foreach ($res as $r) {
         $r->time_bacc = BDToTime($r->time_bacc);
         array_push($listComment, $r);
     }
     if ($comment) {
         $toEdit = $comment;
     } else {
         // On récupère l'utilisateur connecté
         $user = BlogAuth::getUserInfos();
         $toEdit = _record('blogarticlecomment');
         $toEdit->authorid_bacc = $user->userId;
         $toEdit->authorname_bacc = $user->name;
         $toEdit->authoremail_bacc = $user->email;
         $toEdit->authorweb_bacc = $user->web;
     }
     $tpl->assign('blog', $blog);
     $tpl->assign('toEdit', $toEdit);
     $tpl->assign('listComment', $listComment);
     $tpl->assign('errors', $this->getParam('errors', null));
     $tpl->assign('showErrors', $this->getParam('showErrors', false));
     $tpl->assign('canComment', BlogAuth::canComment($blog->id_blog));
     $plugStats = CopixPluginRegistry::get("stats|stats");
     $plugStats->setParams(array('objet_a' => $article->id_bact));
     // retour de la fonction :
     $toReturn = $article->name_bact . '{/}' . $tpl->fetch('showarticle.tpl');
     return true;
 }
 public function _createContent(&$toReturn)
 {
     $tpl = new CopixTpl();
     $blog = $this->getParam('blog', '');
     //on récupère l'ensemble des articles du blog
     $dao = _dao('blog|blogpage');
     $page = $dao->getPageByUrl($blog->id_blog, $this->getParam('page', ''));
     if (!$page) {
         $toReturn = $tpl->fetch('showpage.tpl');
         return true;
     }
     $tpl->assign('page', $page);
     $plugStats = CopixPluginRegistry::get("stats|stats");
     $plugStats->setParams(array('objet_a' => $page->id_bpge));
     // retour de la fonction :
     $toReturn = $tpl->fetch('showpage.tpl');
     return true;
 }
 /**
  * Affiche un minimail en d�tail
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2005/10/18
  * @param integer $id Id du minimail
  */
 public function getMessage()
 {
     $this->addJs('js/iconito/module_minimail.js');
     $MinimailService =& CopixClassesFactory::Create('minimail|MinimailService');
     // 2 DAO -> 2 assign
     $idUser = _currentUser()->getId();
     $idMessage = _request("id");
     $errors = array();
     $daoFrom = CopixDAOFactory::create("minimail_from");
     $daoTo = CopixDAOFactory::create("minimail_to");
     $message = $daoFrom->getMessage($idMessage);
     $dest = $daoTo->selectDestFromId($idMessage);
     $isRecv = $isSend = false;
     if ($message) {
         $message->prev = NULL;
         $message->next = NULL;
     }
     if ($message && $message->from_id == $idUser) {
         // Message qu'il a envoy�
         $message->type = "send";
         $prev = $daoFrom->getFromPrevMessage($message->date_send, $idUser);
         if ($prev) {
             $message->prev = $prev->id;
         }
         $next = $daoFrom->getFromNextMessage($message->date_send, $idUser);
         if ($next) {
             $message->next = $next->id;
         }
         $isSend = true;
     } else {
         // Il en est peut-�tre destinataire
         $isDest = $daoTo->selectDestFromIdAndToUser($idMessage, $idUser);
         // Test s'il est dans les destin
         if ($isDest) {
             $serv = CopixClassesFactory::create("MinimailService");
             $serv->markMinimailAsRead($dest, $idUser);
             $message->type = "recv";
             $prev = $daoTo->getToPrevMessage($message->date_send, $idUser);
             if ($prev) {
                 $message->prev = $prev->id;
             }
             $next = $daoTo->getToNextMessage($message->date_send, $idUser);
             if ($next) {
                 $message->next = $next->id;
             }
             $isRecv = true;
         } else {
             // Il tente d'afficher un message qu'il n'a pas envoy� ni re�u !
             $errors[] = CopixI18N::get('minimail.error.cantDisplay');
         }
     }
     if ($errors) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => implode('<br/>', $errors), 'back' => CopixUrl::get('minimail||')));
     } else {
         $userInfo = Kernel::getUserInfo("ID", $message->from_id);
         $message->from = $userInfo;
         $message->from_id_infos = $userInfo["prenom"] . " " . $userInfo["nom"] . " (" . $userInfo["login"] . ")";
         foreach ($dest as $j => $null) {
             //print_r($dest[$j]->to_id);
             $userInfo = Kernel::getUserInfo("ID", $dest[$j]->to_id);
             $dest[$j]->to = $userInfo;
             $dest[$j]->to_id_infos = $userInfo["prenom"] . " " . $userInfo["nom"] . " (" . $userInfo["login"] . ")";
         }
         // Avatar de l'exp�diteur
         $avatar = Prefs::get('prefs', 'avatar', $message->from_id);
         $message->avatar = $avatar ? CopixConfig::get('prefs|avatar_path') . $avatar : '';
         $tpl = new CopixTpl();
         $tpl->assign('TITLE_PAGE', $message->title);
         $menu = array();
         $menu[] = array('txt' => CopixI18N::get('minimail.mess_recv'), 'url' => CopixUrl::get('minimail||getListRecv'), 'current' => $isRecv);
         $menu[] = array('txt' => CopixI18N::get('minimail.mess_send'), 'url' => CopixUrl::get('minimail||getListSend'), 'current' => $isSend);
         $menu[] = array('txt' => CopixI18N::get('minimail.mess_write'), 'url' => CopixUrl::get('minimail||getNewForm'));
         $tpl->assign('MENU', $menu);
         $message->attachment1IsImage = $MinimailService->isAttachmentImage($message->attachment1);
         $message->attachment2IsImage = $MinimailService->isAttachmentImage($message->attachment2);
         $message->attachment3IsImage = $MinimailService->isAttachmentImage($message->attachment3);
         $message->attachment1Name = $MinimailService->getAttachmentName($message->attachment1);
         $message->attachment2Name = $MinimailService->getAttachmentName($message->attachment2);
         $message->attachment3Name = $MinimailService->getAttachmentName($message->attachment3);
         //print_r($message);
         $tplListe = new CopixTpl();
         $tplListe->assign('message', $message);
         $tplListe->assign('dest', $dest);
         $result = $tplListe->fetch('getmessage.tpl');
         $tpl->assign('MAIN', $result);
         $plugStats = CopixPluginRegistry::get("stats|stats");
         $plugStats->setParams(array('objet_a' => $idMessage));
         return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
     }
 }
 /**
  * Affichage de LA PAGE demand� pour le blog.
  */
 public function getPage()
 {
     if (!_request('blog')) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('blog.error.missingParameters'), 'back' => CopixUrl::get('')));
     }
     //On verifit que le blog existe (on r�cup�re le blog avec son nom)
     $dao = CopixDAOFactory::create('blog|blog');
     if (!($blog = $dao->getBlogByName(_request('blog')))) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('blog.error.unableToFindBlog'), 'back' => CopixUrl::get('')));
     }
     // On v�rifie que le droit de lecture est pr�sent
     if (!BlogAuth::canMakeInBlog('READ', $blog)) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('kernel|kernel.error.noRights'), 'back' => CopixUrl::get('')));
     }
     if (!_request('page')) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('blog.error.missingParameters'), 'back' => CopixUrl::get('blog||', array('blog' => _request('blog')))));
     }
     //		$menu = array();
     $parent = Kernel::getModParentInfo("MOD_BLOG", $blog->id_blog);
     //print_r($parent);
     $blog->parent = $parent;
     /*
             if ($parent['type']=='CLUB') {
                 $droit = Kernel::getLevel($parent['type'], $parent['id']);
                 //print_r($droit);
                 if (GroupeService::canMakeInGroupe('VIEW_HOME', $droit))
                     $menu[] = array('url'=>CopixUrl::get ('groupe||getHome', array("id"=>$parent['id'])), 'txt'=>CopixI18N::get ('blog.menuToGroup'));
             }
             if (BlogAuth::canMakeInBlog('ACCESS_ADMIN',$blog))
                 $menu[] = array('url'=>CopixUrl::get ('admin|showBlog', array("id_blog"=>$blog->id_blog)), 'txt'=>CopixI18N::get ('blog.menuAdmin'));
     */
     $menu = array();
     if (BlogAuth::canMakeInBlog('ACCESS_ADMIN', $blog)) {
         $menu = getBlogAdminMenu($blog);
     }
     CopixHTMLHeader::addCSSLink(CopixUrl::get('blog||getBlogCss', array('id_blog' => $blog->id_blog)));
     $tpl = new CopixTpl();
     $tpl->assign('TITLE_PAGE', $blog->name_blog);
     $tpl->assign('blog', $blog);
     $tpl->assign('MENU', $menu);
     $tpl->assign('Page', CopixZone::process('ShowPage', array('blog' => $blog, 'page' => _request('page'))));
     $tpl->assign('ListLink', CopixZone::process('ListLink', array('blog' => $blog)));
     $tpl->assign('ListCategory', CopixZone::process('ListCategory', array('blog' => $blog)));
     $tpl->assign('ListArchive', CopixZone::process('ListArchive', array('blog' => $blog)));
     $tpl->assign('ListPage', CopixZone::process('ListPage', array('blog' => $blog)));
     $tpl->assign('ListSearch', CopixZone::process('ListSearch', array('blog' => $blog)));
     $tpl->assign('ListFluxRss', CopixZone::process('ListFluxRss', array('blog' => $blog)));
     CopixHtmlHeader::addOthers('<link rel="alternate" href="' . CopixUrl::get('blog||rss', array("blog" => $blog->url_blog)) . '" type="application/rss+xml" title="' . htmlentities($blog->name_blog) . '" />');
     if ($blog->template) {
         $MAIN = $tpl->fetch($blog->template);
     } else {
         $MAIN = $tpl->fetch('blog_main.tpl');
     }
     $tpl->assign('MAIN', $MAIN);
     $tpl->assign('HEADER_MODE', 'compact');
     $plugStats = CopixPluginRegistry::get("stats|stats");
     $plugStats->setParams(array('module_id' => $blog->id_blog, 'parent_type' => $parent['type'], 'parent_id' => $parent['id']));
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }
 /**
  * Page d'accueil d'un groupe
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2005/11/15
  * @param integer $id Id du groupe
  */
 public function getHome()
 {
     $kernel_service =& CopixClassesFactory::Create('kernel|kernel');
     $groupeService =& CopixClassesFactory::Create('groupe|groupeService');
     $id = $this->getRequest('id', null);
     $errors = array();
     $dao = CopixDAOFactory::create("groupe");
     $groupe = $dao->getGroupe($id);
     if (!$groupe) {
         $errors[] = CopixI18N::get('groupe|groupe.error.noGroup');
     }
     $mondroit = $kernel_service->getLevel("CLUB", $id);
     //print_r("mondroit=$mondroit");
     if (!$groupeService->canMakeInGroupe('VIEW_HOME', $mondroit)) {
         $errors[] = CopixI18N::get('kernel|kernel.error.noRights');
     }
     if ($errors) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => implode('<br/>', $errors), 'back' => CopixUrl::get('groupe||')));
     } else {
         // On r�cup�re les modules du groupe
         $his_modules = $kernel_service->getModEnabled("club", $id);
         foreach ($his_modules as $k => $node) {
             //print_r(explode("_",$node->module_type));
             list($tmp, $module) = explode("_", $node->module_type);
             $module = strtolower($module);
             $classeModule = CopixClassesFactory::create("{$module}|Kernel{$module}");
             $infos = $classeModule->getStats($node->module_id);
             //print_r($infos);
             $his_modules[$k]->infos = $infos;
             $his_modules[$k]->module_nom = Kernel::Code2Name($node->module_type);
         }
         // Infos du groupe
         $classeModule = CopixClassesFactory::create("groupe|Kernelgroupe");
         $infos = $classeModule->getStats($id);
         $groupe[0]->infos = $infos;
         $groupe[0]->nbMembers = $infos['nbMembers']['name'];
         $userInfo = $kernel_service->getUserInfo("ID", $groupe[0]->createur);
         $groupe[0]->createur_nom = $userInfo["prenom"] . " " . $userInfo["nom"];
         $groupe[0]->createur_infos = $userInfo;
         //print_r($groupe[0]);
         $tpl = new CopixTpl();
         $tpl->assign('TITLE_PAGE', $groupe[0]->titre);
         // $tpl->assign ('MENU', '<a href="'.CopixUrl::get ('groupe||getListMy').'">'.CopixI18N::get ('groupe|groupe.backMy').'</a>');
         $menu = array();
         //$menu[] = array('url' => CopixUrl::get ('groupe||getListMy'), 'txt'=>CopixI18N::get ('groupe|groupe.backMy'), 'size'=>120);
         $tpl->assign('MENU', $menu);
         $tplHome = new CopixTpl();
         $tplHome->assign('groupe', $groupe[0]);
         $tplHome->assign('canViewAdmin', $groupeService->canMakeInGroupe('ADMIN', $mondroit) ? 1 : 0);
         $tplHome->assign('canUnsubscribeHimself', $groupeService->canMakeInGroupe('UNSUBSCRIBE_HIMSELF', $mondroit) ? 1 : 0);
         $tplHome->assign('his_modules', $his_modules);
         $result = $tplHome->fetch('gethome.tpl');
         $tpl->assign('MAIN', $result);
         $plugStats = CopixPluginRegistry::get("stats|stats");
         $plugStats->setParams(array('module_id' => $groupe[0]->id));
         return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
     }
 }