function process()
 {
     $this->tpl->assign("action", $this->request->getActionName());
     switch ($this->request->getActionName()) {
         case 'add':
             $form = new FormUser($this->tpl);
             $done = $form->process();
             if ($done) {
                 $this->setMessage();
             }
             break;
         case 'mod':
         case 'modCur':
             if ($this->request->getActionName() === 'modCur') {
                 $o_user =& User::getInstance();
                 $userLogin = $o_user->getLogin();
             } else {
                 $userLogin = $this->needAUserSelected();
             }
             if ($userLogin) {
                 $this->tpl->assign('user_selected', $userLogin);
                 $form = new FormUser($this->tpl, $userLogin);
                 $done = $form->process();
                 if ($done) {
                     $this->setMessage();
                 }
             }
             // else needASiteAdminSelected display the site selection form
             break;
         case 'del':
             $login = $this->needAUserSelected();
             if ($login && $login != 'anonymous') {
                 $confirmed = $this->needConfirmation('user', $login);
                 if ($confirmed) {
                     $confUser = new UserConfigDb();
                     $confUser->delUser($login);
                     $this->setMessage();
                 }
             }
             break;
     }
     // case no site installed, do not generate
     if (is_a($this->site, "Site")) {
         $this->site->generateFiles();
     }
 }
 function postProcess()
 {
     $confUser = new UserConfigDb();
     $req =& Request::getInstance();
     $curAction = $req->getActionName();
     if ($curAction === 'modCur') {
         // Verify if we update current user
         if ($this->getSubmitValue('form_login') === $this->login) {
             $currentInfo = User::getInfo($this->login);
             // Verify if old password is ok
             $tmpOldPwd = md5($this->getSubmitValue('form_passwordold'));
             if (@$currentInfo['password'] !== $tmpOldPwd) {
                 // Bad old password
                 trigger_error('Bad old passord!', E_USER_ERROR);
             } else {
                 $info = array('login' => $this->login, 'alias' => $this->getSubmitValue('form_alias'), 'email' => $this->getSubmitValue('form_email'), 'send_mail' => $this->getSubmitValue('form_send_mail') == 'no' ? 0 : 1);
                 $submitPassword = $this->getSubmitValue('form_password');
                 if (!empty($submitPassword) && $submitPassword !== $tmpOldPwd) {
                     $info['password'] = md5($submitPassword);
                 }
                 $curAction = 'mod';
             }
         } else {
             trigger_error('Action not authorized. You can modify only your settings!', E_USER_ERROR);
         }
     } else {
         $info = array('login' => $this->login ? $this->login : $this->getSubmitValue('form_login'), 'alias' => $this->getSubmitValue('form_alias'), 'email' => $this->getSubmitValue('form_email'), 'send_mail' => $this->getSubmitValue('form_send_mail') == 'no' ? 0 : 1);
         if ($curAction == 'mod') {
             $currentInfo = User::getInfo($this->login);
             if ($currentInfo['password'] !== $this->getSubmitValue('form_password')) {
                 $info['password'] = md5($this->getSubmitValue('form_password'));
             }
         } else {
             $info['password'] = md5($this->getSubmitValue('form_password'));
         }
     }
     switch ($curAction) {
         case 'add':
             $confUser->addUser($info);
             break;
         case 'mod':
             $confUser->modUser($info);
             break;
         default:
             trigger_error('Action not specified for User configuration. Were you trying to add, modify, delete? Only YOU know that!', E_USER_ERROR);
             break;
     }
 }
    function showAll()
    {
        $this->tpl->setMainTemplate("structure_mail.tpl");
        $this->request->setModuleName('view_visits_rss');
        $allSiteArchive = DataModel::getSites();
        /**
         * Cache Lite
         */
        $options = array('cacheDir' => DIR_CACHE_MAIL, 'lifeTime' => CACHE_MAIL_LIFETIME);
        $Cache_Lite = new Cache_Lite($options);
        $lang =& Lang::getInstance();
        // case update to 2.2RC1 without executing global info
        if (!defined('INTERFACE_DEFAULT_LANG')) {
            define('INTERFACE_DEFAULT_LANG', 'en-utf-8.php');
        }
        $lang->setNewLang(INTERFACE_DEFAULT_LANG);
        /**
         * Compute mails
         */
        $o_config =& PmvConfig::getInstance();
        foreach ($allSiteArchive as $infoSite) {
            /**
             * php Mailer
             */
            $mail = new MyMailer();
            $mail->IsHTML(true);
            $imgUrl = INCLUDE_PATH . "/themes/default/images/phpmv.png";
            $mail->AddEmbeddedImage($imgUrl, "my-attach", $GLOBALS['lang']['logo_description'], "base64", "image/png");
            $uniqCacheId = md5(serialize($infoSite) . date("Y-m-d")) . '.mail';
            // Test if thereis a valide cache for this id
            if (true) {
                $o_mod = new ViewVisitsRss($infoSite);
                $this->request->date = getDateFromTimestamp(time() - 86400);
                $o_mod->init($this->request);
                $dateLiteral = $o_mod->data->archive->getLiteralDate();
                $body = '<html xml:lang="fr" >
						<head>
							<meta http-equiv="content-type" content="text/html; charset=utf-8" />
						</head>
						
						<body>
						';
                $body .= $o_mod->showAll(true, true);
                $body .= '</body></html>';
                $textBody = strip_tags($body);
                $subject = vsprintf($GLOBALS['lang']['rss_titre'], array($infoSite->getName(), $dateLiteral));
                print "<br>Subject : {$subject}<hr>";
                print "<br>Content : {$body}<hr>";
                //$Cache_Lite->save($body);
            }
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AltBody = $textBody;
            $mail->CharSet = $GLOBALS['lang']['charset'];
            $user = new UserConfigDb();
            $groups = $user->getGroups();
            $users = array_merge(array(0 => array('email' => SU_EMAIL, 'alias' => 'phpMyVisites Administrator', 'send_mail' => SEND_MAIL == "yes" ? 1 : 0)), $user->getUserByGroup(1, $infoSite->getId()), $user->getUserByGroup(2, $infoSite->getId()));
            // we send all emails once
            $emailsToSend_infos = array('object' => $mail, 'to' => array());
            // add recipients for the mail
            foreach ($users as $userInfo) {
                //print_r($userInfo);
                if (!empty($userInfo['email']) && $userInfo['send_mail'] == 1) {
                    $emailsToSend_infos['to'][] = array($userInfo['email'], $userInfo['alias']);
                }
            }
            $emailsToSend[] = $emailsToSend_infos;
        }
        // send all emails
        foreach ($emailsToSend as $currMail) {
            $mail =& $currMail['object'];
            foreach ($currMail['to'] as $recipient) {
                $mail->AddAddress($recipient[0], $recipient[1]);
                if (!@$mail->Send()) {
                    echo "<u><b>There was an error sending the message to " . $userInfo['email'] . "</u></b><br>";
                } else {
                    echo "<u><b>Message was sent successfully to " . $userInfo['email'] . "</u></b><br>";
                }
                $mail->ClearAddresses();
            }
        }
    }