public function checkPrefs($module, $data)
 {
     define('AVATAR_MAX_BYTES', 100000);
     define('AVATAR_MAX_PIXELS', 100);
     $error = array();
     if ($data['passwd1'] != '' || $data['passwd2'] != '') {
         if ($data['passwd1'] != $data['passwd2']) {
             $error['passwd2'] = CopixI18N::get('prefs.config.passwd.error.notsame');
             $error['passwd1'] = " ";
         }
         if (strlen($data['passwd1']) < 5) {
             $error['passwd1'] = CopixI18N::get('prefs.config.passwd.error.tooshort');
         }
     }
     if (isset($_FILES) && $_FILES['prefs_avatar_upload']['name']) {
         if (!in_array($_FILES['prefs_avatar_upload']['type'], array('image/jpeg', 'image/gif', 'image/png'))) {
             $error['avatar_upload'] = CopixI18N::get('prefs.config.avatar.error_format');
         } elseif ($_FILES['prefs_avatar_upload']['size'] > AVATAR_MAX_BYTES) {
             $error['avatar_upload'] = CopixI18N::get('prefs.config.avatar.error_bytes');
         } elseif ((list($width, $height, $type, $attr) = getimagesize($_FILES['prefs_avatar_upload']['tmp_name'])) && max($width, $height) > AVATAR_MAX_PIXELS) {
             $error['avatar_upload'] = CopixI18N::get('prefs.config.avatar.error_pixels');
         } elseif ($_FILES['prefs_avatar_upload']['error'] != 0) {
             $error['avatar_upload'] = CopixI18N::get('prefs.config.avatar.error_inconnue');
         }
     }
     $data['alerte_mail_email'] = trim($data['alerte_mail_email']);
     if (isset($data['alerte_mail_email']) && $data['alerte_mail_email'] != '') {
         // if( !ereg( "@", $data['alerte_mail_email'] ) )
         if (!validateEMail($data['alerte_mail_email'])) {
             $error['alerte_mail_email'] = CopixI18N::get('prefs.config.mail.bad_email');
         }
     }
     return $error;
 }
 /**
  * Envoi d'une intervention a des mails exterieurs
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2009/01/22
  * @param integer $id Id de la procedure
  * @param string $mail_from Expediteur
  * @param string $mail_to Destinataire
  * @param string $mail_cc Copie a
  * @param string $mail_message Message d'accompagnement optionnel
  */
 public function sendMails()
 {
     $id = $this->getRequest('id', null);
     $mail_from = $this->getRequest('mail_from', null);
     $mail_to = $this->getRequest('mail_to', null);
     $mail_cc = $this->getRequest('mail_cc', null);
     $mail_message = $this->getRequest('mail_message', null);
     $daoIntervention = CopixDAOFactory::create("intervention");
     $criticErrors = $errors = array();
     if ($id && ($rFiche = $daoIntervention->get($id))) {
         $title = $rFiche->objet;
         $mondroit = Kernel::getLevel("MOD_TELEPROCEDURES", $rFiche->type_teleprocedure);
         if (!TeleproceduresService::canMakeInTelep('SEND_MAILS', $mondroit, array('idinter' => $rFiche->idinter))) {
             $criticErrors[] = CopixI18N::get('kernel|kernel.error.noRights');
         }
     } else {
         $criticErrors[] = CopixI18N::get('teleprocedures|teleprocedures.error.prob.telep');
     }
     if (!CopixConfig::get('|mailEnabled')) {
         $criticErrors[] = CopixI18N::get('teleprocedures|teleprocedures.error.noMailEnabled');
     }
     if ($criticErrors) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => implode('<br/>', $criticErrors), 'back' => CopixUrl::get('teleprocedures||')));
     }
     $fiche = CopixZone::process('fiche', array('rFiche' => $rFiche, 'print' => 1));
     $ecoleInfos = Kernel::getNodeInfo('BU_ECOLE', $rFiche->idetabliss, false);
     $errors = $ok = null;
     require_once COPIX_UTILS_PATH . 'CopixUtils.lib.php';
     if (!$mail_from) {
         $errors = CopixI18N::get('teleprocedures|teleprocedures.error.mail_from', '');
     } else {
         $list = preg_split("/[\\s,]+/", $mail_from);
         foreach ($list as $email) {
             if (!validateEMail($email)) {
                 $errors .= CopixI18N::get('teleprocedures|teleprocedures.error.incorrectMail', $email) . "\n";
             }
         }
     }
     if (!$mail_to) {
         $errors = CopixI18N::get('teleprocedures|teleprocedures.error.mail_to', '');
     } else {
         $list = preg_split("/[\\s,]+/", $mail_to);
         foreach ($list as $email) {
             if (!validateEMail($email)) {
                 $errors .= CopixI18N::get('teleprocedures|teleprocedures.error.incorrectMail', $email) . "\n";
             }
         }
     }
     if ($mail_cc) {
         $list = preg_split("/[\\s,]+/", $mail_cc);
         foreach ($list as $email) {
             if (!validateEMail($email)) {
                 $errors .= CopixI18N::get('teleprocedures|teleprocedures.error.incorrectMail', $email) . "\n";
             }
         }
     }
     if ($errors) {
         return CopixActionGroup::process('teleprocedures|default::fiche', array('id' => $id, 'errors' => $errors, 'rFiche' => array('mail_from' => $mail_from, 'mail_to' => $mail_to, 'mail_cc' => $mail_cc, 'mail_message' => $mail_message)));
     }
     if (!$errors) {
         require_once COPIX_UTILS_PATH . 'CopixEMailer.class.php';
         $from = $fromName = $mail_from;
         $to = $mail_to;
         $cc = $cci = null;
         if ($mail_cc) {
             $cc = $mail_cc;
         }
         $subject = $rFiche->objet . ' / ' . $rFiche->type_nom . ' / ' . $rFiche->ecole_nom;
         if ($rFiche->ecole_type) {
             $subject .= ' (' . $rFiche->ecole_type . ')';
         }
         $de = _currentUser()->getExtra('prenom') . ' ' . _currentUser()->getExtra('nom');
         $message = '';
         $message .= "<p>L'intervention suivante vous est transmise par " . $de . ".</p>";
         if ($mail_message) {
             $message .= '<p>' . nl2br($mail_message) . '</p><hr/>';
         }
         $message .= $fiche;
         //$from = CopixConfig::get('|mailFrom');
         //$fromName = CopixConfig::get('|mailFromName');
         $mail = new CopixHtmlEMail($to, $cc, $cci, utf8_decode($subject), utf8_decode($message));
         $send = $mail->send($from, $fromName);
         if (!$send) {
             $errors = CopixI18N::get('teleprocedures|teleprocedures.error.sendMail');
         } else {
             $ok = CopixI18N::get('teleprocedures|teleprocedures.ok.sendMail', $mail_to);
             $info_commentaire = "Mail envoy&eacute; de {$from} &agrave; {$to}";
             if ($cc) {
                 $info_commentaire .= " (copie &agrave; {$cc})";
             }
             if ($mail_message) {
                 $info_commentaire .= " - Message d'acompagnement : " . $mail_message . "";
             }
             $rFiche->insertInfoSupp(null, $info_commentaire);
         }
     }
     //var_dump($send);
     if ($errors) {
         $errors = str_replace("\n", "<br/>", trim($errors));
     }
     if ($ok) {
         $ok = $ok;
     }
     return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('|fiche', array('id' => $id, 'errors' => $errors, 'ok' => $ok)));
     //return CopixActionGroup::process ('teleprocedures|default::fiche', array ('id'=>$id, 'errors'=>$errors));
 }
 /**
  * Formulaire de saisie/modif d'un type de teleprocedure
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2009/01/15
  * @param integer $save 1 si submit du formulaire
  */
 public function formtype()
 {
     $idtype = $this->getRequest('idtype');
     $teleprocedure = $this->getRequest('teleprocedure');
     $save = $this->getRequest('save');
     $daoType =& CopixDAOFactory::create('teleprocedures|type');
     $criticErrors = $errors = array();
     $tplForm = new CopixTpl();
     $tplForm->assign('is_online', array('values' => array(1, 0), 'output' => array(CopixI18N::get('blog|blog.oui'), CopixI18N::get('blog|blog.non'))));
     $formats = CopixConfig::get('teleprocedures|formats_types');
     $tabFormats = preg_split('/[\\s,]+/', $formats);
     $values = $output = array();
     foreach ($tabFormats as $k) {
         $values[] = $k;
         $output[] = CopixI18N::get('blog|blog.default_format_articles.' . $k);
     }
     $tplForm->assign('format', array('values' => $values, 'output' => $output));
     $tplForm->assign('linkpopup_responsables', CopixZone::process('annuaire|linkpopup', array('field' => 'responsables', 'profil' => 'USER_VIL')));
     $tplForm->assign('linkpopup_lecteurs', CopixZone::process('annuaire|linkpopup', array('field' => 'lecteurs', 'profil' => 'USER_VIL')));
     // Verifications
     if ($idtype) {
         if ($rType = $daoType->get($idtype)) {
             $mondroit = Kernel::getLevel("MOD_TELEPROCEDURES", $rType->teleprocedure);
             if (!TeleproceduresService::canMakeInTelep('ADMIN', $mondroit)) {
                 $criticErrors[] = CopixI18N::get('kernel|kernel.error.noRights');
             }
         } else {
             $criticErrors[] = CopixI18N::get('teleprocedures|teleprocedures.error.noParameter');
         }
     } elseif ($teleprocedure) {
         $mondroit = Kernel::getLevel("MOD_TELEPROCEDURES", $teleprocedure);
         if (!TeleproceduresService::canMakeInTelep('ADMIN', $mondroit)) {
             $criticErrors[] = CopixI18N::get('kernel|kernel.error.noRights');
         }
     } else {
         $criticErrors[] = CopixI18N::get('teleprocedures|teleprocedures.error.noParameter');
     }
     if ($criticErrors) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => implode('<br/>', $criticErrors), 'back' => CopixUrl::get('teleprocedures||')));
     }
     // Traitement
     if ($idtype) {
         // Modif
         $title = CopixI18N::get('teleprocedures|teleprocedures.title.modifType');
         if ($save) {
             // Responsables
             $responsables = $this->getRequest('responsables');
             $responsables = str_replace(array(" "), "", $responsables);
             $responsables = str_replace(array(",", ";"), ",", $responsables);
             $responsables = preg_split('/[\\s,]+/', $responsables);
             $tabResponsables = array();
             $deja = array();
             // On vérifie que les membres existent
             while (list(, $login) = each($responsables)) {
                 if (!$login) {
                     continue;
                 }
                 $userInfo = Kernel::getUserInfo("LOGIN", $login);
                 if (!$userInfo) {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoUser', array($login));
                 } elseif ($userInfo['type'] != 'USER_VIL') {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoVille', array($login));
                 } else {
                     $tabResponsables[] = $userInfo;
                     $deja[] = $login;
                 }
             }
             //print_r($tabResponsables);
             // Lecteurs
             $lecteurs = $this->getRequest('lecteurs');
             $lecteurs = str_replace(array(" "), "", $lecteurs);
             $lecteurs = str_replace(array(",", ";"), ",", $lecteurs);
             $lecteurs = preg_split('/[\\s,]+/', $lecteurs);
             $tabLecteurs = array();
             // On vérifie que les membres existent
             while (list(, $login) = each($lecteurs)) {
                 if (!$login) {
                     continue;
                 }
                 $userInfo = Kernel::getUserInfo("LOGIN", $login);
                 if (!$userInfo) {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoUser', array($login));
                 } elseif ($userInfo['type'] != 'USER_VIL') {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoVille', array($login));
                 } elseif (in_array($login, $deja)) {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberDeja', array($login));
                 } else {
                     $tabLecteurs[] = $userInfo;
                 }
             }
             $type = $rType;
             $type->nom = $this->getRequest('nom');
             $type->is_online = $this->getRequest('is_online');
             $type->teleprocedure = $this->getRequest('teleprocedure');
             $type->format = $this->getRequest('format');
             $type->texte_defaut = $this->getRequest('texte_defaut');
             $type->responsables = $this->getRequest('responsables');
             $type->lecteurs = $this->getRequest('lecteurs');
             $type->mail_from = $this->getRequest('mail_from');
             $type->mail_to = $this->getRequest('mail_to');
             $type->mail_cc = $this->getRequest('mail_cc');
             $type->mail_message = $this->getRequest('mail_message');
             if ($type->mail_from && !validateEMail($type->mail_from)) {
                 $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.incorrectMail', $type->mail_from);
             }
             if ($type->mail_to) {
                 $list = preg_split('/[\\s,]+/', $type->mail_to);
                 foreach ($list as $email) {
                     if (!validateEMail($email)) {
                         $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.incorrectMail', $email);
                     }
                 }
             }
             if ($type->mail_cc) {
                 $list = preg_split('/[\\s,]+/', $type->mail_cc);
                 foreach ($list as $email) {
                     if (!validateEMail($email)) {
                         $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.incorrectMail', $email);
                     }
                 }
             }
             if ($type->mail_to && !$type->mail_from) {
                 $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.mail_from');
             }
             $errorsDao = _dao('teleprocedures|type')->check($type);
             //die();
             if (count($errors) || is_array($errorsDao)) {
                 // Erreurs
                 if (is_array($errorsDao)) {
                     $errors = array_merge($errorsDao, $errors);
                 }
             } else {
                 // Pas d'erreurs
                 $daoType->update($type);
                 TeleproceduresService::saveDroits("type", $idtype, 'responsables', $tabResponsables);
                 TeleproceduresService::saveDroits("type", $idtype, 'lecteurs', $tabLecteurs);
                 return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('admin|admin', array('id' => $type->teleprocedure)));
             }
         } else {
             $type = $rType;
         }
     } else {
         // Creation
         $title = CopixI18N::get('teleprocedures|teleprocedures.title.newType');
         $type = CopixDAOFactory::createRecord('teleprocedures|type');
         if ($save) {
             // Responsables
             $responsables = $this->getRequest('responsables');
             $responsables = str_replace(array(" "), "", $responsables);
             $responsables = str_replace(array(",", ";"), ",", $responsables);
             $responsables = preg_split('/[\\s,]+/', $responsables);
             $tabResponsables = array();
             while (list(, $login) = each($responsables)) {
                 if (!$login) {
                     continue;
                 }
                 $userInfo = Kernel::getUserInfo("LOGIN", $login);
                 if (!$userInfo) {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoUser', array($login));
                 } elseif ($userInfo['type'] != 'USER_VIL') {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoVille', array($login));
                 } else {
                     $tabResponsables[] = $userInfo;
                     $deja[] = $login;
                 }
             }
             // Lecteurs
             $lecteurs = $this->getRequest('lecteurs');
             $lecteurs = str_replace(array(" "), "", $lecteurs);
             $lecteurs = str_replace(array(",", ";"), ",", $lecteurs);
             $lecteurs = preg_split('/[\\s,]+/', $lecteurs);
             $tabLecteurs = array();
             // On vérifie que les membres existent
             while (list(, $login) = each($lecteurs)) {
                 if (!$login) {
                     continue;
                 }
                 $userInfo = Kernel::getUserInfo("LOGIN", $login);
                 if (!$userInfo) {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoUser', array($login));
                 } elseif ($userInfo['type'] != 'USER_VIL') {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberNoVille', array($login));
                 } elseif (in_array($login, $deja)) {
                     $errors[] = CopixI18N::get('teleprocedures|teleprocedures.error.memberDeja', array($login));
                 } else {
                     $tabLecteurs[] = $userInfo;
                 }
             }
             $type->nom = $this->getRequest('nom');
             $type->is_online = $this->getRequest('is_online');
             $type->teleprocedure = $this->getRequest('teleprocedure');
             $type->format = $this->getRequest('format');
             $type->texte_defaut = $this->getRequest('texte_defaut');
             $type->responsables = $this->getRequest('responsables');
             $type->lecteurs = $this->getRequest('lecteurs');
             $type->mail_from = $this->getRequest('mail_from');
             $type->mail_to = $this->getRequest('mail_to');
             $type->mail_cc = $this->getRequest('mail_cc');
             $type->mail_message = $this->getRequest('mail_message');
             $errorsDao = _dao('teleprocedures|type')->check($type);
             if (count($errors) || is_array($errorsDao)) {
                 // Erreurs
                 if (is_array($errorsDao)) {
                     $errors = array_merge($errorsDao, $errors);
                 }
             } else {
                 // Pas d'erreurs
                 $daoType->insert($type);
                 if ($type->idtype) {
                     TeleproceduresService::saveDroits("type", $type->idtype, 'responsables', $tabResponsables);
                     TeleproceduresService::saveDroits("type", $type->idtype, 'lecteurs', $tabLecteurs);
                 }
                 return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('admin|admin', array('id' => $type->teleprocedure)));
             }
         } else {
             $type->teleprocedure = $teleprocedure;
             $type->is_online = 1;
             $type->format = CopixConfig::get('teleprocedures|default_format');
         }
     }
     //print_r($type);
     $tplForm->assign('type', $type);
     $tplForm->assign('edition_texte_defaut', CopixZone::process('kernel|edition', array('field' => 'texte_defaut', 'format' => $type->format, 'content' => $type->texte_defaut, 'height' => 460)));
     $tplForm->assign('errors', $errors);
     $tplForm->assign('mailEnabled', CopixConfig::get('|mailEnabled'));
     $main = $tplForm->fetch('form-type.tpl');
     $tpl = new CopixTpl();
     $tpl->assign('TITLE_PAGE', $title);
     $tpl->assign("MAIN", $main);
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }