예제 #1
0
    $debug = false;
    if (@$argv[1] == 'debug') {
        $debug = true;
    }
    $results = Database::singleton()->query_fetch_all($sql);
    foreach ($results as &$campaign) {
        $campaign = new Campaign($campaign['id']);
        switch ($campaign->calcStatus(true)) {
            case 2:
                break;
            case 1:
                $sql = 'SELECT aut_email FROM auth WHERE aut_agp_id = ' . $campaign->getGroup() . ' LIMIT 1';
                $email = Database::singleton()->query_fetch($sql);
                $email = $email['aut_email'];
                $sql = 'SELECT agp_name FROM auth_groups WHERE agp_id = ' . $campaign->getGroup();
                $group = Database::singleton()->query_fetch($sql);
                $group = $group['agp_name'];
                $campaign->mailOut('votes', $group, $email);
                if ($debug) {
                    echo "Sent " . $campaign->getName() . " emails.\n";
                }
            default:
                $sql = 'UPDATE campaigns SET autosend = 0 WHERE id = ' . $campaign->getId();
                $result = Database::singleton()->query($sql);
                if ($debug) {
                    echo "Removed " . $campaign->getName() . "'s autosend.\n";
                }
                break;
        }
    }
}
예제 #2
0
 function getAdminInterface()
 {
     $this->addJS('/modules/Campaigns/js/voteadmin.js');
     $this->addCSS('/modules/Campaigns/css/campaign.css');
     switch (@$_REQUEST['section']) {
         case 'addedit':
             if ($this->user->hasPerm('addcampaign')) {
                 $campaign = new Campaign(@$_REQUEST['campaign_id']);
                 $form = $campaign->getAddEditForm();
                 $this->smarty->assign('form', $form);
                 $this->smarty->assign('status', $campaign->getId());
                 if ($form->isSubmitted() && isset($_REQUEST['submit'])) {
                     if ($form->validate()) {
                         return $this->topLevelAdmin();
                     }
                 }
                 return $this->smarty->fetch('admin/campaigns_addedit.tpl');
             }
             return $this->smarty->fetch('../../../cms/templates/error.tpl');
         case 'campaigndelete':
             $campaign = new Campaign($_REQUEST['campaign_id']);
             if ($this->user->hasPerm('addcampaign') && $this->user->getAuthGroup() == $campaign->getGroup() && strpos($campaign->getStatus(), 'pcoming') > 0) {
                 $campaign->delete();
                 unset($campaign);
                 return $this->topLevelAdmin();
             }
             return $this->smarty->fetch('../../../cms/templates/error.tpl');
         case 'viewresults':
             if ($this->user->hasPerm('viewcampaign')) {
                 $campaign = new Campaign($_REQUEST['campaign_id']);
                 $this->smarty->assign('campaign', $campaign);
                 $campaign->addResultViewer($this->user->getId());
                 return $this->smarty->fetch('admin/campaign_results.tpl');
             }
             return $this->smarty->fetch('admin/campaign_recips_addedit.tpl');
         case 'questionedit':
             if ($this->user->hasPerm('addcampaign')) {
                 $campaign = new Campaign($_REQUEST['campaign_id']);
                 $this->smarty->assign('campaign', $campaign);
                 if (isset($_REQUEST['choices_submit'])) {
                     if (!is_null(@$_REQUEST['choice'])) {
                         foreach ($_REQUEST['choice'] as $key => $achoice) {
                             if (is_numeric($key)) {
                                 $choice = new CampaignChoice($key);
                                 if (!empty($achoice['main'])) {
                                     $choice->setCampaign($_REQUEST['campaign_id']);
                                     $choice->setChoice($achoice['main']);
                                     $choice->save();
                                     if (is_array(@$_REQUEST['choice'][$key])) {
                                         $choice->createChildren($_REQUEST['choice'][$key]);
                                     }
                                 } else {
                                     $choice->delete();
                                 }
                             }
                         }
                     }
                     if (!is_null(@$_REQUEST['nChoice'])) {
                         if (isset($_REQUEST['nChoice'])) {
                             foreach ($_REQUEST['nChoice'] as $key => $achoice) {
                                 if (!empty($achoice['main'])) {
                                     $choice = new CampaignChoice();
                                     $choice->setCampaign($_REQUEST['campaign_id']);
                                     $choice->setChoice($achoice['main']);
                                     $choice->save();
                                     if (is_array(@$_REQUEST['nChoice'][$key])) {
                                         $choice->createChildren($_REQUEST['nChoice'][$key]);
                                     }
                                 }
                             }
                         }
                     }
                     return $this->topLevelAdmin();
                 }
                 return $this->smarty->fetch('admin/campaign_choices_addedit.tpl');
             }
             return $this->smarty->fetch('../../../cms/templates/error.tpl');
         case 'reciplist':
             return $this->recipTopLevelAdmin();
         case 'recipaddedit':
             if ($this->user->hasPerm('addcampaignrecips')) {
                 if (!is_null(@$_REQUEST['recipient_id'])) {
                     $recipient = new CampaignUser($_REQUEST['recipient_id']);
                 } else {
                     $recipient = new CampaignUser();
                     $recipient->setGroup($this->user->getAuthGroup());
                 }
                 $form = $recipient->getAddEditForm();
                 $this->smarty->assign('form', $form);
                 if ($form->isSubmitted() && isset($_REQUEST['submit'])) {
                     if ($form->validate()) {
                         return $this->recipTopLevelAdmin();
                     }
                 }
                 return $this->smarty->fetch('admin/campaign_recips_addedit.tpl');
             }
             return $this->smarty->fetch('../../../cms/templates/error.tpl');
         case 'recipcsvup':
             if ($this->user->hasPerm('addcampaignrecips')) {
                 $form = Campaign::getCSVForm();
                 $this->smarty->assign('form', $form);
                 if ($form->validate() && $form->isSubmitted() && $_POST['submit']) {
                     return $this->recipTopLevelAdmin();
                 }
                 return $this->smarty->fetch('admin/campaign_csvup.tpl');
             }
             return $this->smarty->fetch('../../../cms/templates/error.tpl');
         case 'recipdelete':
             if ($this->user->hasPerm('addcampaignrecips')) {
                 if (!is_null($_REQUEST['id']) && CampaignUser::exists($_REQUEST['id'])) {
                     $recipient = new CampaignUser($_REQUEST['id']);
                     if ($recipient->getGroup() == $this->user->getAuthGroup()) {
                         $recipient->delete();
                         unset($_REQUEST['id']);
                     } else {
                         return $this->smarty->fetch('../../../cms/templates/error.tpl');
                     }
                 }
                 return $this->recipTopLevelAdmin();
             }
             return $this->smarty->fetch('../../../cms/templates/error.tpl');
         case 'votesend':
             if ($this->user->hasPerm('addcampaignrecips')) {
                 $campaign = new Campaign($_REQUEST['campaign_id']);
                 return $campaign->mailOut('votes');
             }
             return 'You do not have permission to perform this action.';
         case 'voteprint':
             if ($this->user->hasPerm('generatereciplist')) {
                 $campaign = new Campaign($_REQUEST['campaign_id']);
                 $campaign->preparePdf();
             }
             return $this->topLevelAdmin();
         case 'resultsend':
             if ($this->user->hasPerm('addcampaignrecips')) {
                 $campaign = new Campaign($_REQUEST['campaign_id']);
                 return $campaign->mailOut('results');
             }
             return 'You do not have permission to perform this action.';
         case 'listbilling':
             if ($this->user->hasPerm('admin')) {
                 $groups = Group::getGroups();
                 $this->smarty->assign('groups', $groups);
                 return $this->smarty->fetch('admin/billing_list.tpl');
             }
         case 'viewbilling':
             if ($this->user->hasPerm('admin')) {
                 $group = new Group($_REQUEST['group_id']);
                 $this->smarty->assign('group', $group);
                 $campaigns = Campaign::getCampaigns($_REQUEST['group_id']);
                 $campaignsSorted = array_merge($campaigns['upcoming'], $campaigns['progress'], $campaigns['ended']);
                 $this->smarty->assign('campaigns', $campaignsSorted);
                 return $this->smarty->fetch('admin/billing_view.tpl');
             }
         case 'togglestatus':
             if ($this->user->hasPerm('admin')) {
                 $group = new Group($_REQUEST['group_id']);
                 if ($group->getStatus() > 0) {
                     $group->setStatus(0);
                 } else {
                     $group->setStatus(1);
                 }
                 $group->save();
             }
             $groups = Group::getGroups();
             $this->smarty->assign('groups', $groups);
             return $this->smarty->fetch('admin/billing_list.tpl');
             break;
         case 'whovoted':
             if ($this->user->hasPerm('addcampaign')) {
                 $campaign = new Campaign($_REQUEST['campaign_id']);
                 $this->smarty->assign('votedlist', $campaign->userVotedList());
                 $this->smarty->assign('notvotedlist', $campaign->userVotedList(false));
                 $this->smarty->assign('campaignName', $campaign->getName());
                 return $this->smarty->fetch('admin/voted_list.tpl');
             }
             return $this->topLevelAdmin();
         case 'archivecampaign':
             if ($this->user->hasPerm('addcampaign')) {
                 $campaign = new Campaign($_REQUEST['campaign_id']);
                 $campaign->setArchiveStatus(1);
                 $campaign->save();
             }
             return $this->topLevelAdmin();
         case 'viewarchive':
             if ($this->user->hasPerm('viewcampaign')) {
                 $campaigns = Campaign::getCampaigns($this->user->getAuthGroup(), 1, 'endDate ASC');
                 $this->smarty->assign('campaigns', $campaigns);
                 $this->smarty->assign('company', $this->user->getAuthGroupName());
                 return $this->smarty->fetch('admin/campaign_archive.tpl');
             }
             return $this->topLevelAdmin();
         default:
             if ($this->user->hasPerm('admin') && !$this->user->hasPerm('viewcampaign')) {
                 header("Location: /admin/Campaigns&section=listbilling");
             }
             return $this->topLevelAdmin();
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     Yii::app()->theme = 'client';
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->returnUrl);
     } else {
         $email = isset($_GET['email']) ? $_GET['email'] : '';
         $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : '';
         if ($email && $activkey) {
             $form2 = new UserChangePassword();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Incorrect recovery link."));
                 $this->redirect(Yii::app()->controller->module->recoveryUrl);
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $user->activkey = UserModule::encrypting(microtime() . $user->password);
                     $user->save();
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     /*
                     						$this->createUrl(implode(Yii::app()->controller->module->recoveryUrl));
                     						$subject = UserModule::t("You have requested the password recovery site {site_name}",
                     		    					array(
                     		    						'{site_name}'=>Yii::app()->name,
                     		    					));
                     		    			$message = UserModule::t("You have requested the password recovery site {site_name}. To receive a new password, go to <a href=\"{activation_url}\">{activation_url}</a>.",
                     		    					array(
                     		    						'{site_name}'=>Yii::app()->name,
                     		    						'{activation_url}'=>$activation_url,
                     		    					));
                     							
                     		    			UserModule::sendMail($user->email,$subject,$message);
                     */
                     // новая служба системных сообщений
                     $type_id = Emails::TYPE_10;
                     $email = new Emails();
                     /*$criteria = new CDbCriteria();
                     		$criteria->order = 'id DESC';
                     		$criteria->limit = 1;
                     		$user = User::model()->findAll($criteria);
                     		$user = $user[0];*/
                     $email->from_id = 1;
                     $email->to_id = $form->user_id;
                     //  = $user->id;
                     $rec = Templates::model()->findAll("`type_id`='{$type_id}'");
                     $id = Campaign::getId();
                     $email->campaign = Campaign::getName();
                     $email->name = $user->full_name;
                     $email->login = $user->username;
                     $email->password = $soucePassword;
                     $email->page_psw = $activation_url;
                     $email->page_cabinet = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit';
                     $email->sendTo($user->email, $rec[0]->title, $rec[0]->text, $type_id);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     if (isset($_GET['role']) && $_GET['role'] == 'Customer') {
         $role = 'Customer';
     } elseif (isset($_GET['role']) && $_GET['role'] == 'Author') {
         $role = 'Author';
     } elseif (isset($_GET['role']) && $_GET['role'] == 'Manager') {
         $role = 'Manager';
     } else {
         $role = 'Customer';
     }
     if (Yii::app()->user->id && (!Yii::app()->user->hasFlash('reg_success') && !Yii::app()->user->hasFlash('reg_failed'))) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             if ($model->validate()) {
                 $soucePassword = $this->generate_password(8);
                 $model->password = UserModule::encrypting($soucePassword);
                 $model->superuser = 0;
                 $model->status = 1;
                 $model->username = $model->email;
                 if ($model->save()) {
                     $AuthAssignment = new AuthAssignment();
                     $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id);
                     $AuthAssignment->save();
                     //$login_url = '<a href="'.$this->createAbsoluteUrl('/user/login').'">'.Yii::app()->name.'</a>';
                     //UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("You have registred from {login_url}<br /><br />Your password: {pass}",array('{login_url}'=>$login_url, '{pass}'=>$soucePassword)));
                     // новая служба системных сообщений
                     $type_id = Emails::TYPE_11;
                     $email = new Emails();
                     $criteria = new CDbCriteria();
                     $criteria->order = 'id DESC';
                     $criteria->limit = 1;
                     $user = User::model()->findAll($criteria);
                     $user = $user[0];
                     $email->from_id = 1;
                     $email->to_id = $user->id;
                     $rec = Templates::model()->findAll("`type_id`='{$type_id}'");
                     $title = $rec[0]->title;
                     $body = $rec[0]->text;
                     $id = Campaign::getId();
                     $email->campaign = Campaign::getName();
                     $email->name = $model->full_name;
                     $email->login = $model->username;
                     $email->password = $soucePassword;
                     $email->page_cabinet = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit';
                     $email->sendTo($user->email, $body, $type_id);
                     $identity = new UserIdentity($model->username, $soucePassword);
                     $identity->authenticate();
                     Yii::app()->user->login($identity, 0);
                     //$this->redirect(Yii::app()->controller->module->returnUrl);
                     Yii::app()->user->setFlash('reg_success', UserModule::t("Thank you for your registration. Password has been sent to your e-mail. Please check your e-mail ({{email}}) before start.", ['{{email}}' => $model->email]));
                     $this->refresh();
                     //Yii::app()->end();
                 } else {
                     Yii::app()->user->setFlash('reg_failed', UserModule::t("Sorry, something wrong... :("));
                     $this->refresh();
                 }
             }
         }
         Yii::app()->theme = 'client';
         $this->render('/user/registration', array('model' => $model, 'role' => $role));
     }
 }
예제 #5
0
 public static function getByEmail($addr)
 {
     if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.([a-zA-Z]{2,4})$', $addr)) {
         $sql = 'SELECT id FROM campaign_recipients WHERE email = \'' . e($addr) . "'";
         $result = Database::singleton()->query_fetch_all($sql);
         if ($result && count($result) == 1) {
             $id = $result[0]['id'];
             $sql = 'INSERT INTO campaign_hash_requests SET IP = \'' . $_SERVER['REMOTE_ADDR'] . '\', email = \'' . e($addr) . '\'';
             Database::singleton()->query($sql);
             $sql = 'SELECT hash,campaign_id FROM campaign_hash WHERE user_id = ' . $id;
             $results = Database::singleton()->query_fetch_all($sql);
             $body = "This e-mail address was used to request the retrieval of hash keys on the SafeBallot system. " . "If you believe you have received this message in error, please contact the person in charge of voting " . "campaigns at your organization and ensure to keep the original copy of this contact.\n\nHash keys:\n";
             if ($results) {
                 for ($i = 0; $i < count($results); $i++) {
                     $cid = $results[$i]["campaign_id"];
                     $hash = $results[$i]["hash"];
                     $campaign = new Campaign($cid);
                     if ($campaign->calcStatus(true) == 1) {
                         $body .= "\nCampaign '" . $campaign->getName() . "' -> " . $hash;
                     }
                 }
             } else {
                 $body .= "There are currently no voting campaigns in progress.";
             }
             mail($addr, 'Hash Key Retrieval', $body, "From: Safeballot <*****@*****.**>");
             return true;
         }
     }
     return false;
 }