/**
  * Etablissement d'un challenge, sur la base d'un identifiant SSO
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2006/12/08
  * @param integer $id_sso Id SSO
  * @return string résultat du challenge. -ERR xxx si erreur, +OK xxx si c'est bon
  */
 public function challenge()
 {
     $id_sso = $this->getRequest('id_sso', null);
     if (!$id_sso) {
         echo "-ERR ACC: id_sso manquant";
     } elseif (!preg_match('/^[0-9]+$/', $id_sso)) {
         echo "-ERR ACC: id_sso doit être un nombre";
     } else {
         $token = false;
         $sql = "SELECT login FROM kernel_sso_users WHERE id_sso = {$id_sso}";
         $sso = _doQuery($sql);
         //print_r($sso);
         if ($sso) {
             // On efface l'éventuel challenge courant
             $daoChallenges = CopixDAOFactory::create('sso|sso_challenges');
             $daoChallenges->deleteByIdSso($id_sso);
             // On insère le nouveau challenge
             $token = randomkeys(CopixConfig::get('sso|in_encrypt_size'));
             $res = record('kernel_sso_challenges');
             $res->id_sso = $id_sso;
             $res->challenge = $token;
             $res->date = mktime();
             _ioDao('kernel_sso_challenges')->insert($record);
             //print_r($res);
             // if ($res->_idResult != 1)	{ echo "-ERR BDD: Erreur lors de l'enregistrement dans la base de données"; }
             //Kernel::deb (md5($token.'FobVVbarwb'));
             //die();
             $token = "+OK " . $token;
         } else {
             echo "-ERR ACC: id_sso inexistant";
         }
         echo $token;
     }
     return new CopixActionReturn(COPIX_AR_NONE, 0);
 }
 /**
  * constructor.
  */
 function CopixGroup($id)
 {
     //look for the capability values for the given group
     $this->id_cgrp = $id;
     if ($id !== null) {
         //check if the group exists.
         $daoGroup =& CopixDAOFactory::create('copix:CopixGroup');
         $group =& $daoGroup->get($id);
         if ($group === null) {
             trigger_error('Given group does not exists');
         }
         $this->description_cgrp = $group->description_cgrp;
         $this->name_cgrp = $group->name_cgrp;
         $this->all_cgrp = $group->all_cgrp;
         $this->known_cgrp = $group->known_cgrp;
         $daoCap =& CopixDAOFactory::create('copix:CopixGroupCapabilities');
         $sp =& CopixDAOFactory::createSearchParams();
         $sp->addCondition('id_cgrp', '=', $id);
         //load capabilities.
         $capabilities = $daoCap->findBy($sp);
         foreach ($capabilities as $capability) {
             $this->setCapability($capability->name_ccpb, $capability->value_cgcp);
         }
         //load logins
         $daoUserGroup =& CopixDAOFactory::create('copix:CopixUserGroup');
         $sp =& CopixDAOFactory::createSearchParams();
         $sp->addCondition('id_cgrp', '=', $id);
         $logins = $daoUserGroup->findBy($sp);
         //adds the logins in the object
         foreach ($logins as $login) {
             $this->addUsers($login->login_cusr);
         }
     }
 }
 function getLignes()
 {
     $dao = CopixDAOFactory::create('adresseligne');
     $criteres = CopixDAOFactory::createSearchConditions();
     $criteres->addCondition('id_adresse', '=', $this->id);
     return $dao->findBy($criteres);
 }
 public function _createContent(&$toReturn)
 {
     $tpl = new CopixTpl();
     $blog = $this->getParam('blog', '');
     $cat = $this->getParam('cat', null);
     $critere = $this->getParam('critere', null);
     //on récupère l'ensemble des articles du blog
     $dao = _dao('blog|blogarticle');
     if ($cat == null) {
         $date = $this->getParam('date', null);
         $arData = $dao->getAllArticlesFromBlog($blog->id_blog, $date);
     } else {
         $arData = $dao->getAllArticlesFromBlogByCat($blog->id_blog, $cat->id_bacg);
         $tpl->assign('cat', $cat);
     }
     //on filtre si on a fait une recherche sur les articles
     if ($critere != null) {
         $arData = $dao->getAllArticlesFromBlogByCritere($blog->id_blog, $critere);
     }
     //var_dump($arData);
     //on construit un tableau associatif entre l'identifiant de l'article et le nombre de commentaires
     foreach ($arData as $article) {
         //var_dump($article);
         $daoArticleComment =& CopixDAOFactory::getInstanceOf('blog|blogarticlecomment');
         $record = _record('blog|blogarticlecomment');
         $criteres = _daoSp();
         $criteres->addCondition('id_bact', '=', $article->id_bact);
         $criteres->addCondition('is_online', '=', 1);
         $resultat = $daoArticleComment->findBy($criteres);
         $arNbCommentByArticle[$article->id_bact] = count($resultat);
     }
     if (count($arData) > 0) {
         //encodage des URL des catégories pour caractères spéciaux
         foreach ($arData as $key => $data) {
             //Modification suite à apparition d'un warning due à l'absence de catégories , vboniface 06.11.2006
             $arData[$key]->key = $key;
             if (isset($arData[$key]->categories)) {
                 foreach ($arData[$key]->categories as $keyCat => $categorie) {
                     $arData[$key]->categories[$keyCat]->url_bacg = urlencode($categorie->url_bacg);
                 }
             }
         }
         if (count($arData) <= intval(CopixConfig::get('blog|nbMaxArticles'))) {
             $tpl->assign('pager', "");
             $tpl->assign('listArticle', $arData);
             $tpl->assign('arNbCommentByArticle', $arNbCommentByArticle);
         } else {
             $params = array('perPage' => intval(CopixConfig::get('blog|nbMaxArticles')), 'delta' => 5, 'recordSet' => $arData, 'template' => '|pager.tpl');
             $Pager = CopixPager::Load($params);
             $tpl->assign('pager', $Pager->GetMultipage());
             $tpl->assign('listArticle', $Pager->data);
             $tpl->assign('arNbCommentByArticle', $arNbCommentByArticle);
         }
         //rajout suite à bug mantis 54 vboniface 06.11.2006
         $tpl->assign('blog', $blog);
     }
     // retour de la fonction :
     $toReturn = $tpl->fetch('listarticle.tpl');
     return true;
 }
 function _createContent(&$toReturn)
 {
     $tpl =& new CopixTpl();
     $dao =& CopixDAOFactory::create('Comment');
     $sp =& CopixDAOFactory::createSearchConditions();
     $sp->addCondition('id_cmt', '=', $this->params['id']);
     $sp->addCondition('type_cmt', '=', $this->params['type']);
     $sp->addItemOrder('position_cmt', 'desc');
     $arData = $dao->findBy($sp);
     if (count($arData) > 0) {
         $perPage = isset($this->params['perPage']) ? intval($this->params['perPage']) : intval(CopixConfig::get('comment|perPage'));
         $params = array('perPage' => $perPage, 'delta' => 5, 'recordSet' => $arData, 'template' => '|pager.tpl');
         $Pager = CopixPager::Load($params);
         $tpl->assign('pager', $Pager->GetMultipage());
         $tpl->assign('comments', $Pager->data);
     }
     $tpl->assign('back', $this->params['back']);
     $tpl->assign('id', $this->params['id']);
     $tpl->assign('type', $this->params['type']);
     $adminEnabled = CopixUserProfile::valueOf('site', 'siteAdmin') >= PROFILE_CCV_MODERATE;
     $tpl->assign('adminEnabled', $adminEnabled);
     $plugAuth =& $GLOBALS['COPIX']['COORD']->getPlugin('auth|auth');
     $user =& $plugAuth->getUser();
     $tpl->assign('login', $user->login);
     $toReturn = $tpl->fetch('comment.list.tpl');
     return true;
 }
 function getList()
 {
     $dao =& CopixDAOFactory::create('copix:CopixCapability');
     $sp =& CopixDAOFactory::createSearchParams();
     $sp->orderBy('name_ccpb');
     return $dao->findBy($sp);
 }
 function _createContent(&$toReturn)
 {
     $tpl =& new CopixTpl();
     //getting the group list from the database.
     $daoGroups =& CopixDAOFactory::create('copix:CopixGroup');
     $tpl->assign('groups', $daoGroups->findAll());
     $toReturn = $tpl->fetch('profile.adminlist.tpl');
     return true;
 }
 function _createContent(&$toReturn)
 {
     $tpl =& new CopixTpl();
     $dao = CopixDAOFactory::create('emailcat');
     $tpl->assign('listeEmailCat', $dao->findAll());
     // retour de la fonction :
     $toReturn = $tpl->fetch('saisiePers.tpl');
     return true;
 }
 public function test()
 {
     $tpl = new CopixTpl();
     $tpl->assign('TITLE_PAGE', "Logs");
     $dao = CopixDAOFactory::create("logs|logs");
     $data = $dao->lastLogin('admin');
     $tpl->assign('MAIN', '<pre>' . print_r($data, true) . '</pre>');
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }
 function _createContent(&$toReturn)
 {
     $tpl =& new CopixTpl();
     $dao = CopixDAOFactory::create('personne');
     //Préparation de la liste des personnes
     $tpl->assign('listePers', $dao->findAll());
     // retour de la fonction :
     $toReturn = $tpl->fetch('pers.tpl');
     return true;
 }
 /**
  * includes the compiled
  */
 function fileInclude($DAOid)
 {
     $instance =& CopixDAOFactory::instance();
     $DAOid = $instance->_fullQualifier($DAOid);
     //si oui, compilation et retour.
     if ($instance->_needsCompilation($DAOid)) {
         require_once COPIX_DAO_PATH . 'CopixDAOCompiler.class.php';
         $compiler =& new CopixDAOCompiler();
         $compiler->compile($DAOid);
     }
     require_once $instance->_getCompiledPath($DAOid);
 }
 /**
  * includes the compiled
  */
 function fileInclude($DAOid)
 {
     $instance =& CopixDAOFactory::instance();
     $conf =& $GLOBALS['COPIX']['CONFIG'];
     //si oui, compilation et retour.
     if ($instance->_needsCompilation($DAOid)) {
         require_once COPIX_DAO_PATH . 'CopixDAOCompiler.class.php';
         $compiler =& new CopixDAOCompiler();
         $compiler->compile($DAOid);
     }
     require_once $instance->getCompiledPath($DAOid);
 }
 function _createContent(&$toReturn)
 {
     $tpl =& new CopixTpl();
     $dao = CopixDAOFactory::create('personne');
     $criteres = CopixDAOFactory::createSearchConditions();
     $idPers = $this->params['idPers'];
     $criteres->addCondition('id', '=', $idPers);
     $listePers = $dao->findBy($criteres);
     $tpl->assign('personne', $listePers[0]);
     $toReturn = $tpl->fetch('detailpers.tpl');
     return true;
 }
 function _createContent(&$toReturn)
 {
     //Création du sous template.
     $tpl =& new CopixTpl();
     $daoGroups =& CopixDAOFactory::create('copix:CopixGroup');
     $tpl->assign('groups', $daoGroups->findAll());
     $tpl->assign('select', $this->params['select']);
     $tpl->assign('back', $this->params['back']);
     //fetch & end
     $toReturn = $tpl->fetch('group.select.tpl');
     return true;
 }
 public function getSwitchUser()
 {
     $login = _request('login');
     if ($login != '') {
         $me_info = Kernel::getUserInfo("ME", 0);
         $animateurs_dao =& CopixDAOFactory::create("kernel|kernel_animateurs");
         $animateur = $animateurs_dao->get($me_info['type'], $me_info['id']);
         $ien_dao =& CopixDAOFactory::create("kernel|kernel_ien");
         $ien = $ien_dao->get($me_info['type'], $me_info['id']);
         // echo "<pre>"; print_r($ien); die("</pre>");
         if (!$ien && (!$animateur || !isset($animateur->can_connect) || !$animateur->can_connect)) {
             return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('assistance||users', array('error' => 'forbidden')));
         }
         $user_info = Kernel::getUserInfo("LOGIN", $login);
         // $user_info->user_id
         if (!$user_info) {
             return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('assistance||users', array('error' => 'forbidden')));
         }
         $ok = false;
         $assistance_service =& CopixClassesFactory::Create('assistance|assistance');
         $user_assistance = $assistance_service->getAssistanceUsers();
         if (!$user_assistance) {
             return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('assistance||users', array('error' => 'forbidden')));
         }
         foreach ($user_assistance as $ville_id => $ville) {
             foreach ($ville as $ecole_id => $ecole) {
                 foreach ($ecole->personnels as $personnel_id => $personnel) {
                     if ($personnel->id_copix == $user_info['user_id']) {
                         $ok = $personnel->assistance;
                     }
                 }
             }
         }
         if (!$ok) {
             return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('assistance||users', array('error' => 'forbidden')));
         }
         $currentUserLogin = _currentUser()->getLogin();
         CopixSession::destroyNamespace('default');
         _sessionSet('user_animateur', $currentUserLogin);
         _sessionSet('prisedecontrole_ien', $ien ? true : false);
         _currentUser()->login(array('login' => $login, 'assistance' => true));
         $url_return = CopixUrl::get('kernel||doSelectHome');
     } else {
         if ($session = _sessionGet('user_animateur')) {
             CopixSession::destroyNamespace('default');
             //_sessionSet('user_animateur', null);
             _currentUser()->login(array('login' => $session, 'assistance' => true));
         }
         $url_return = CopixUrl::get('assistance||users');
     }
     return new CopixActionReturn(COPIX_AR_REDIRECT, $url_return);
 }
 public function _createContent(&$toReturn)
 {
     $agendaService = new AgendaService();
     $serviceDate = new DateService();
     //on détermine le jour d'affichage
     if ($this->getParam('day') == null) {
         $day = date('Ymd');
     } else {
         $day = $this->getParam('day');
     }
     //on récupère les évènements de la journée
     foreach ($this->getParam('arAgendasAffiches') as $idAgenda) {
         $arEventsSemaine[$idAgenda] = $agendaService->checkEventOfAgendaInBdd($idAgenda, $day, $day);
     }
     //on ordonne les évènements par ordre croissant d'heure de début d'évènement dans la journée
     $arEventByDay = $agendaService->getEventsByDay($arEventsSemaine, $day, $day);
     $arEventByDay = $agendaService->getEventsInOrderByDay($arEventByDay);
     //on simplifie le tableau pour le passer à la zone
     $arDayEvent = $arEventByDay[$day]->events;
     //on récupère la couleur d'affichage de chaque évènement
     //$arColorByEvent = $agendaService->getColorByIdEvent($arDayEvent);
     $arAgendas = $agendaService->getTilteAgendaByIdAgenda($this->getParam('arAgendasAffiches'));
     //on récupère la couleur d'affichage pour chaque agenda
     $boolCroise = array();
     $daoAgenda =& CopixDAOFactory::getInstanceOf('agenda|agenda');
     foreach ($this->getParam('arAgendasAffiches') as $id) {
         $agenda = $daoAgenda->get($id);
         $boolCroise[$agenda->type_agenda] = $boolCroise[$agenda->type_agenda] == false;
         $colors = $agendaService->getColorAgendaByIdAgenda($id);
         $arColorAgenda[$id] = $boolCroise[$agenda->type_agenda] ? $colors[0] : $colors[1];
     }
     $arEventToDisplay = array();
     foreach ($arDayEvent as $event) {
         $event->color = $arColorAgenda[$event->id_agenda];
         $arEventToDisplay[] = $event;
     }
     $jour = substr($day, 6, 2);
     $mois = $serviceDate->moisNumericToMoisLitteral(substr($day, 4, 2));
     $annee = substr($day, 0, 4);
     $tpl = new CopixTpl();
     $tpl->assign('jour', $jour);
     $tpl->assign('mois', $mois);
     $tpl->assign('annee', $annee);
     //$tpl->assign('arEvent'       , $arDayEvent);
     $tpl->assign('arEvent', $arEventToDisplay);
     $tpl->assign('arAgendas', $arAgendas);
     $tpl->assign('arColorByEvent', $arColorByEvent);
     $tpl->assign('arColorAgenda', $arColorAgenda);
     $toReturn = $tpl->fetch('aujourdhui.agenda.tpl');
     return true;
 }
 /**
  * @param $this->params['event'] string the event name
  */
 function _createContent(&$toReturn)
 {
     //new tpl
     $tpl =& new CopixTpl();
     //Search only for the given event.
     $dao =& CopixDAOFactory::create('CopixListener');
     $sp = CopixDAOFactory::createSearchParams('event', '=', $this->params['event']);
     $sp = CopixDAOFactory::createSearchParams('kind', '=', 'zone');
     $list = $dao->findBy($sp);
     //go through the founded listeners, asks for their processing
     foreach ($list as $toProcess) {
         $toReturn .= CopixZone::process($toProcess, $this->params);
     }
     return true;
 }
 /**
  * Redefinition de la méthode delete par défaut du DAO
  * Cette méthode efface en cascade tous les enregistrements
  * associés à une personne lors de l'effacement de cette
  * personne.
  * @param $id L'id de la personne à effacer 
  */
 function delete($id)
 {
     $personne = $this->_compiled->get($id);
     $daoEmails = CopixDAOFactory::create('email');
     $emails = $personne->getEmails();
     foreach ($emails as $email) {
         $daoEmails->delete($email->id);
     }
     $daoAdresses = CopixDAOFactory::create('adresse');
     $adresses = $personne->getAdresses();
     foreach ($adresses as $adresse) {
         $daoAdresses->delete($adresse->id);
     }
     $this->_compiled->_compiled_delete($id);
 }
 /**
  * Création d'un agenda
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2006/08/24
  * @param array $infos (option) informations permettant d'initialiser le blog. Index: title, node_type, node_id
  * @return integer l'Id de l'agenda créé ou NULL si erreur
  */
 public function create($infos = array())
 {
     $daoAgenda =& CopixDAOFactory::getInstanceOf('agenda|agenda');
     $res = null;
     $agenda = _record('agenda|agenda');
     if ($infos['title']) {
         $agenda->title_agenda = $infos['title'];
     } else {
         //$agenda->title_agenda = CopixI18N::get ('agenda|agenda.default.title');
         $agenda->title_agenda = "Agenda";
     }
     $agenda->desc_agenda = $agenda->title_agenda;
     $agenda->type_agenda = AgendaType::getAgendaTypeForNode($infos['node_type'], $infos['node_id']);
     $daoAgenda->insert($agenda);
     return $agenda->id_agenda !== NULL ? $agenda->id_agenda : NULL;
 }
 public function getHomePage()
 {
     if (!Kernel::isAdmin()) {
         return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('||'));
     }
     $tpl = new CopixTpl();
     $tplRegroupements = new CopixTpl();
     // CopixHTMLHeader::addCSSLink (_resource("styles/module_grvilles.css"));
     // $tpl->assign ('TITLE_PAGE', CopixI18N::get ('grvilles|grvilles.module.titre'));
     $dao_grvilles = CopixDAOFactory::create("regroupements|grvilles");
     $grvilles = $dao_grvilles->findAll();
     $tplRegroupements->assign('GRVILLES', count($grvilles));
     $dao_grecoles = CopixDAOFactory::create("regroupements|grecoles");
     $grecoles = $dao_grecoles->findAll();
     $tplRegroupements->assign('GRECOLES', count($grecoles));
     $main = $tplRegroupements->fetch('default.tpl');
     $tpl->assign('MAIN', $main);
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }
 function _createContent(&$toReturn)
 {
     $tpl =& new CopixTpl();
     $dao =& CopixDAOFactory::create('comment|comment');
     $sp =& CopixDAOFactory::createSearchConditions();
     $sp->addItemOrder('date_cmt', 'desc');
     $sp->addItemOrder('position_cmt', 'desc');
     $arComments = array();
     $arComments = $dao->findby($sp);
     if (count($arComments) > 0) {
         $perPage = intval(CopixConfig::get('comment|quickAdminPerPage'));
         $params = array('perPage' => $perPage, 'delta' => 5, 'recordSet' => $arComments, 'template' => '|pager.tpl');
         $pager = CopixPager::Load($params);
         $tpl->assign('pager', $pager->GetMultipage());
         $tpl->assign('comments', $pager->data);
     }
     $toReturn = $lastComments === array() ? '' : $tpl->fetch('comment.quickadmin.tpl');
     return true;
 }
 /**
  * The profile manager.
  */
 function CopixProfile($login)
 {
     $daoGroup =& CopixDAOFactory::create('copix:CopixUserGroup');
     $sp =& CopixDAOFactory::createSearchParams();
     //specific groups.
     $sp->addCondition('login_cusr', '=', $login);
     $groups = $daoGroup->findBy($sp);
     foreach ($groups as $group) {
         $this->_groups[$group->id_cgrp] =& new CopixGroup($group->id_cgrp);
     }
     //public or known user's groups
     $daoGroup =& CopixDAOFactory::create('copix:CopixGroup');
     $sp =& CopixDAOFactory::createSearchParams();
     $sp->addCondition('all_cgrp', '=', 1);
     if ($login !== null) {
         $sp->addCondition('known_cgrp', '=', 1, 'or');
     }
     $groups = $daoGroup->findBy($sp);
     foreach ($groups as $group) {
         $this->_groups[$group->id_cgrp] =& new CopixGroup($group->id_cgrp);
     }
 }
function smarty_function_commentthis($params, &$smarty)
{
    extract($params);
    if (empty($displaytype)) {
        $displaytype = 'list';
    }
    if (empty($type)) {
        $smarty->trigger_error('commentthis: missing type parameter');
    }
    if (empty($id)) {
        $smarty->trigger_error('commentthis: missing id parameter');
    }
    if (empty($dest)) {
        $dest = CopixUrl::get('comment||getList', array('type' => $type, 'id' => $id, 'back' => $back));
    }
    $dao =& CopixDAOFactory::create('comment|Comment');
    $services =& CopixClassesFactory::create('comment|commentservices');
    $services->enableComment($id, $type);
    switch ($displaytype) {
        case 'link':
            $nbComment = $dao->getNbComment($id, $type);
            $toReturn = '<a href=' . $dest . '>' . $nbComment . ' ';
            $toReturn .= $nbComment > 1 ? CopixI18N::get('comment|comment.messages.comments') : CopixI18N::get('comment|comment.messages.comment');
            $toReturn .= '</a>';
            break;
        case 'form':
            $back = CopixUrl::getCurrentUrl();
            CopixActionGroup::process('comment|comment::doPrepareAdd', array('type' => $type, 'id' => $id, 'back' => $back));
            $toEdit = CopixActionGroup::process('comment|comment::_getSessionComment');
            $toReturn = CopixZone::process('comment|AddComment', array('toEdit' => $toEdit));
            break;
        case 'list':
        default:
            $toReturn = CopixZone::process('comment|CommentList', array('type' => $type, 'id' => $id));
            break;
    }
    return $toReturn;
}
 /**
  * Ajout d'une info supplementaire
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2008/01/30
  * @param integer $id Id de la procedure
  */
 public function insertInfoSupp()
 {
     $id = $this->getRequest('id', null);
     $info_message = $this->getRequest('info_message', null);
     $info_commentaire = $this->getRequest('info_commentaire', null);
     $visible = $this->getRequest('visible', null);
     $daoIntervention = CopixDAOFactory::create("intervention");
     $daoInfoSupp = CopixDAOFactory::create("infosupp");
     $criticErrors = $errors = array();
     if ($id && ($rFiche = $daoIntervention->get($id))) {
         $title = $rFiche->objet;
         $mondroit = Kernel::getLevel("MOD_TELEPROCEDURES", $rFiche->type_teleprocedure);
         if (!TeleproceduresService::canMakeInTelep('ADD_COMMENT', $mondroit)) {
             $criticErrors[] = CopixI18N::get('kernel|kernel.error.noRights');
         }
     } else {
         $criticErrors[] = CopixI18N::get('teleprocedures|teleprocedures.error.prob.telep');
     }
     if ($criticErrors) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => implode('<br/>', $criticErrors), 'back' => CopixUrl::get('teleprocedures||')));
     }
     if ($info_message || $info_commentaire) {
         //$canCheckVisible = TeleproceduresService::canMakeInTelep('CHECK_VISIBLE', $mondroit);
         $rFiche->insertInfoSupp($info_message, $info_commentaire);
     }
     return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('|fiche', array('id' => $id)));
 }
 public function getGroup()
 {
     if (!Kernel::isAdmin()) {
         return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('||'));
     }
     $tpl = new CopixTpl();
     $tplGrVilles = new CopixTpl();
     CopixHTMLHeader::addCSSLink(_resource("styles/module_regroupements.css"));
     $regroupements_service =& CopixClassesFactory::Create('regroupements|regroupements');
     $tpl->assign('TITLE_PAGE', CopixI18N::get('regroupements|regroupements.villes.titre'));
     $tpl->assign('MENU', $regroupements_service->getMenu());
     $dao_grvilles_gr2ville = CopixDAOFactory::create("regroupements|grvilles_gr2ville");
     $dao_grvilles = CopixDAOFactory::create("regroupements|grvilles");
     $dao_villes = CopixDAOFactory::create("kernel|kernel_tree_vil");
     $villes = $dao_villes->findAll();
     $tplGrVilles->assign('villes', $villes);
     if (_request("delete")) {
         $dao_grvilles->delete(_request("delete"));
         $dao_grvilles_gr2ville->deleteByGroupe(_request("delete"));
         return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('regroupements|villes|'));
     }
     if (_request("save") && _request("save") == 1) {
         $date = date("Y-m-d H:i:s");
         $user = Kernel::getUserInfo();
         if (_request("form_id") > 0) {
             $grvilles_infos = $dao_grvilles->get(_request("form_id"));
             $grvilles_infos->nom = _request("form_nom");
             $grvilles_infos->updated_at = $date;
             $grvilles_infos->updated_by = $user['login'];
             $dao_grvilles->update($grvilles_infos);
             $dao_grvilles_gr2ville->deleteByGroupe(_request("form_id"));
         } else {
             $grvilles_infos = CopixDAOFactory::createRecord("regroupements|grvilles");
             $grvilles_infos->nom = _request("form_nom");
             if ($grvilles_infos->nom == '') {
                 $grvilles_infos->nom = 'Sans nom';
             }
             $grvilles_infos->updated_at = date("Y-m-d H:i:s");
             $grvilles_infos->updated_by = $user['login'];
             $dao_grvilles->insert($grvilles_infos);
         }
         $grvilles_gr2ville = _record("regroupements|grvilles_gr2ville");
         $grvilles_gr2ville->id_groupe = $grvilles_infos->id;
         $grvilles_gr2ville->updated_at = $date;
         $grvilles_gr2ville->updated_by = $user['login'];
         foreach ($villes as $ville) {
             if (_request("ville_" . $ville->vil_id_vi) == 1) {
                 $grvilles_gr2ville->id_ville = $ville->vil_id_vi;
                 _dao("regroupements|grvilles_gr2ville")->insert($grvilles_gr2ville);
             }
         }
         if (_request("form_id") == 0) {
             return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('regroupements|villes|', array('groupe' => $grvilles_infos->id)));
         }
     }
     if (_request("groupe")) {
         $tplGrVilles->assign('grvilles_id', _request("groupe"));
         $tplGrVilles->assign('grvilles_form', true);
         if (_request("groupe") > 0) {
             // Edition d'un groupe
             $grvilles_infos = $dao_grvilles->get(_request("groupe"));
             $grvilles_villes_raw = $dao_grvilles_gr2ville->findByGroupe(_request("groupe"));
             // Tableau indexé par id de ville
             $grvilles_villes = array();
             foreach ($grvilles_villes_raw as $grvilles_villes_item) {
                 $grvilles_villes[$grvilles_villes_item->id_ville] = $grvilles_villes_item;
             }
             $tplGrVilles->assign('grvilles_infos', $grvilles_infos);
             $tplGrVilles->assign('grvilles_villes', $grvilles_villes);
         } else {
             // Création d'un nouveau groupe
         }
     }
     $grvilles_list = $dao_grvilles->findAll();
     // print_r($grvilles_list);
     $tplGrVilles->assign('grvilles_list', $grvilles_list);
     $main = $tplGrVilles->fetch('getgrvilles.tpl');
     $tpl->assign('MAIN', $main);
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }
 /**
  * Téléchargement d'une pièce jointe dans un classeur
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2012/06/21
  * @param integer $id Id du minimail de départ
  */
 public function attachmentToClasseur()
 {
     //_dump($_POST);
     $this->addJs('js/iconito/module_classeur.js');
     $this->addJs('js/iconito/module_minimail.js');
     $this->addCss('styles/module_classeur.css');
     _classInclude('classeur|classeurService');
     _classInclude('kernel|Request');
     $idUser = _currentUser()->getId();
     $idMessage = _request("id");
     $files = _request('files', array());
     $destination = _request('destination');
     $errors = array();
     $daoFrom = _ioDAO("minimail|minimail_from");
     $daoTo = CopixDAOFactory::create("minimail_to");
     $message = $daoFrom->getMessage($idMessage);
     $canMake = $isRecv = $isSend = false;
     if ($message && $message->from_id == $idUser) {
         // Message qu'il a envoyé
         $canMake = $isSend = true;
     } else {
         // Il en est peut-être destinataire
         $canMake = $isRecv = $daoTo->selectDestFromIdAndToUser($idMessage, $idUser);
         // Test s'il est dans les destin
     }
     if (!$canMake) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('minimail.error.cantDisplay'), 'back' => CopixUrl::get('minimail||')));
     }
     $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'));
     $ppo = new CopixPPO();
     $ppo->TITLE_PAGE = $message;
     $ppo->MENU = $menu;
     $ppo->message = $message;
     //_dump(Request::isXmlHttpRequest());
     if (Request::isPostMethod()) {
         $error = $success = array();
         if (!$files) {
             $error[] = CopixI18N::get('minimail.attachmentToClasseur.error.noFiles');
         }
         if ($destination) {
             list($ppo->destinationType, $ppo->destinationId) = explode('-', $destination);
             if ('classeur' == $ppo->destinationType) {
                 $rClasseur = _ioDAO('classeur|classeur')->get($ppo->destinationId);
             }
             if ('dossier' == $ppo->destinationType) {
                 if ($rDossier = _ioDAO('classeur|classeurdossier')->get($ppo->destinationId)) {
                     $rClasseur = _ioDAO('classeur|classeur')->get($rDossier->classeur_id);
                 }
             }
         }
         if (!$destination || !$rClasseur) {
             $error[] = CopixI18N::get('classeur|classeur.error.noDestination');
         }
         if ($error) {
             $ppo->error = $error;
             return _arPPO($ppo, array('template' => 'attachmentToClasseur.tpl', 'mainTemplate' => 'main|main_popup.php'));
         }
         //_dump($destination);
         //_dump($rClasseur);
         $dir = realpath('./static/classeur') . '/' . $rClasseur->id . '-' . $rClasseur->cle . '/';
         if (!file_exists($dir)) {
             mkdir($dir, 0755, true);
         }
         foreach ($files as $file) {
             $fichierPhysique = realpath("../var/data") . "/minimail/" . $file;
             $nomFichierPhysique = $file;
             $fichier = _record('classeur|classeurfichier');
             $fichier->classeur_id = $rClasseur->id;
             $fichier->dossier_id = isset($rDossier) && $rDossier ? $rDossier->id : 0;
             $fichier->titre = MinimailService::getAttachmentName($file);
             $fichier->fichier = $nomFichierPhysique;
             $fichier->taille = filesize($fichierPhysique);
             $fichier->type = strtoupper(substr(strrchr($nomFichierPhysique, '.'), 1));
             $fichier->cle = classeurService::createKey();
             $fichier->date_upload = date('Y-m-d H:i:s');
             $fichier->user_type = _currentUser()->getExtra('type');
             $fichier->user_id = _currentUser()->getExtra('id');
             _ioDAO('classeur|classeurfichier')->insert($fichier);
             if ($fichier->id > 0) {
                 $nomClasseur = $rClasseur->id . '-' . $rClasseur->cle;
                 $nomFichier = $fichier->id . '-' . $fichier->cle;
                 $extension = strtolower(strrchr($nomFichierPhysique, '.'));
                 if (copy($fichierPhysique, $dir . $fichier->id . '-' . $fichier->cle . $extension)) {
                     $success[] = MinimailService::getAttachmentName($file);
                 } else {
                     $error[] = CopixI18N::get('minimail.attachmentToClasseur.error.moved', array(MinimailService::getAttachmentName($file)));
                 }
             } else {
                 $error[] = CopixI18N::get('minimail.attachmentToClasseur.error.creation', array(MinimailService::getAttachmentName($file)));
             }
         }
         if (count($success) > 0) {
             $dest = $rClasseur;
             if (isset($rDossier) && $rDossier) {
                 $dest .= ' / ' . $rDossier;
             }
             if (1 == count($success)) {
                 Kernel::setFlashMessage('success', CopixI18N::get('minimail.attachmentToClasseur.moved_1', array(implode(', ', $success), $dest)));
             } else {
                 Kernel::setFlashMessage('success', CopixI18N::get('minimail.attachmentToClasseur.moved_N', array(implode(', ', $success), $dest)));
             }
         }
         if ($error) {
             Kernel::setFlashMessage('error', implode('<br />', $error));
         }
         $ppo->ok = 1;
         //echo 'OK';
         //return _arNone();
         //return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('minimail||getMessage', array('id' => $idMessage)));
     }
     return _arPPO($ppo, array('template' => 'attachmentToClasseur.tpl', 'mainTemplate' => 'main|main_popup.php'));
 }
 /**
  * Store data
  *
  * @access private
  */
 function storeData($entityName)
 {
     $_entityName = $entityName;
     $_httpRequest =& HttpRequest::instance();
     $_session =& HttpSession::instance();
     $_tagged = $_session->getAttribute('TAGGED');
     $_index = $_session->getAttribute('INDEX');
     $_create = $_index < 0;
     $_next = false;
     if ($_httpRequest->getAttribute('accept')) {
         $_httpRequest->removeAttribute('accept');
         $_new = $_httpRequest->getAttribute('ENTITY');
         foreach ($_session->getAttribute('ENTITY') as $_key => $_value) {
             $_old[$_key] = $_value;
         }
         $_equal = true;
         foreach ($_new as $_key => $_value) {
             if ($_value !== $_old[$_key]) {
                 $_updated[$_key] = $_value;
                 $_equal = false;
             } else {
                 $_updated[$_key] = $_old[$_key];
             }
         }
         if (!$_equal) {
             $_dao =& CopixDAOFactory::create($_entityName);
             if ($_create) {
                 $_entity =& CopixDAOFactory::createRecord($_entityName);
                 foreach ($_updated as $_key => $_value) {
                     $_entity->{$_key} = $_value;
                 }
                 $_dao->insert($_entity);
                 $_connection =& CopixDbFactory::getConnection();
                 $_tagged[] = $_connection->lastId();
             } else {
                 // update
                 $_dlname = 'get' . $_entityName . 'DataList';
                 $_dataList = $this->{$_dlname}();
                 $_idLabel = $_dataList['id']['var'];
                 $_entity = $_dao->get($_updated[$_idLabel]);
                 foreach ($_updated as $_key => $_value) {
                     $_entity->{$_key} = $_value;
                 }
                 $_dao->update($_entity);
             }
         }
         ++$_index;
         // next one ?
         $_next = $_create || $_index < sizeOf($_tagged);
     } elseif ($_httpRequest->getAttribute('cancel')) {
         $_httpRequest->removeAttribute('cancel');
         ++$_index;
         // next one ?
         $_next = !$_create && $_index < sizeOf($_tagged);
     } else {
         // always return to the list
     }
     if ($_next) {
         $_session->setAttribute('INDEX', $_index);
         $_httpRequest->removeAttribute('ENTITY');
         $_forward = $_create ? 'create' : 'update';
         $_httpRequest->setAttribute($_forward, $_forward);
         // $_httpRequest->setAttribute('TAGGED', $_tagged);
         // TODO: la méthode CopixUrl::getUrl ne gère pas correctement les tableaux, d'où :
         foreach ($_tagged as $_key => $_Id) {
             $_httpRequest->setAttribute('TAGGED[' . $_key . ']', $_Id);
         }
         $_requestUrl = new ProjectUrl('manage' . $_entityName . 'Data', null, 'workflow', $_httpRequest->toArray());
     } else {
         $_requestUrl = new ProjectUrl('show' . $_entityName . 'List', null, 'workflow');
     }
     return new CopixActionReturn(COPIX_AR_REDIRECT, $_requestUrl->getUrl(false));
 }
 /**
  * Test d'une DAO automatique
  */
 public function testDAOAuto()
 {
     CopixDAOFactory::getInstanceOf('copixtestautodao')->findAll();
 }
 /**
  * Affichage de la fiche d'une ecole
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2008/09/03
  * @param integer $id Id de l'ecole
  */
 public function blogs()
 {
     $id = $this->getRequest('id', null);
     $pAnnee = $this->getRequest('annee', null);
     //
     $ecoleDAO = CopixDAOFactory::create('kernel|kernel_bu_ecole');
     $ficheDAO = CopixDAOFactory::create("fiches_ecoles");
     $criticErrors = array();
     if (!($rEcole = $ecoleDAO->get($id))) {
         $criticErrors[] = CopixI18N::get('fichesecoles.error.param');
     } elseif (!FichesEcolesService::canMakeInFicheEcole($id, 'VIEW')) {
         $criticErrors[] = CopixI18N::get('kernel|kernel.error.noRights');
     }
     if ($criticErrors) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => implode('<br/>', $criticErrors), 'back' => CopixUrl::get('annuaire||')));
     }
     $arClasses = AnnuaireService::getClassesInEcole($rEcole->numero, array('forceCanViewEns' => true, 'onlyWithBlog' => true, 'onlyWithBlogIsPublic' => 1, 'enseignant' => false, 'annee' => $pAnnee));
     $rEcole->blog = getNodeBlog('BU_ECOLE', $rEcole->numero, array('is_public' => 1));
     // Get vocabulary catalog to use
     $nodeVocabularyCatalogDAO = _ioDAO('kernel|kernel_i18n_node_vocabularycatalog');
     $vocabularyCatalog = $nodeVocabularyCatalogDAO->getCatalogForNode('BU_ECOLE', $id);
     $tpl = new CopixTpl();
     $tpl->assign('rEcole', $rEcole);
     $tpl->assign('arClasses', $arClasses);
     $tpl->assign('catalog', $vocabularyCatalog->id_vc);
     if ($anneeDebutBlogs = CopixConfig::get('fichesecoles|anneeDebutBlogs')) {
         $anneeFinBlogs = Kernel::getAnneeScolaireCourante()->id_as;
         //Kernel::deb("anneeDebutBlogs=$anneeDebutBlogs / anneeFinBlogs=$anneeFinBlogs");
         if (!$pAnnee) {
             $pAnnee = $anneeFinBlogs;
         }
         if ($anneeFinBlogs > $anneeDebutBlogs) {
             $comboAnnees = CopixZone::process('kernel|combo_annees', array('name' => 'annee', 'selected' => $pAnnee, 'debut' => $anneeDebutBlogs, 'fin' => $anneeFinBlogs, 'extra2' => 'onChange="ficheViewBlogs(' . $id . ',this.options[this.selectedIndex].value);"'));
             $tpl->assign('comboAnnees', $comboAnnees);
         }
     }
     $result = $tpl->fetch('blogs.tpl');
     header('Content-type: text/html; charset=utf-8');
     //echo utf8_encode($result);
     echo $result;
     return new CopixActionReturn(COPIX_AR_NONE, 0);
 }
 public function getDelete()
 {
     if (!Kernel::isAdmin()) {
         return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('||'));
     }
     $pUserType = _request('user_type');
     $pUserId = _request('user_id');
     if (!$pUserType || !$pUserId) {
         return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('comptes|animateurs|list'));
     }
     $animateurs_dao =& CopixDAOFactory::create("kernel|kernel_animateurs");
     // $animateurs2grville_dao = & CopixDAOFactory::create("kernel|kernel_animateurs2grville");
     $animateurs2regroupements_dao =& CopixDAOFactory::create("kernel|kernel_animateurs2regroupements");
     $animateurs_dao->delete($pUserType, $pUserId);
     // $animateurs2grville_dao->deleteByUser($pUserType, $pUserId);
     $animateurs2regroupements_dao->deleteByUser($pUserType, $pUserId);
     return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('comptes|animateurs|list'));
 }