コード例 #1
0
 public function notifyAdmin()
 {
     $tos = array();
     if ($this->getToId()) {
         $email = $this->getTo()->getSwiftEmail();
         if ($email) {
             $tos[] = $email;
         }
     }
     if (!$tos && $this->getPetitionId()) {
         $prs = PetitionRightsTable::getInstance()->queryByPetitionAndAdmin($this->getPetition())->execute();
         foreach ($prs as $pr) {
             /* @var $pr PetitionRights */
             if ($pr->getUser()->isCampaignMember($this->getPetition()->getCampaign())) {
                 $email = $pr->getUser()->getSwiftEmail();
                 if ($email) {
                     $tos[] = $email;
                 }
             }
         }
     }
     if (!$tos && $this->getCampaignId()) {
         $crs = CampaignRightsTable::getInstance()->queryByCampaignAndAdmin($this->getCampaign())->execute();
         foreach ($crs as $cr) {
             /* @var $cr CampaignRights */
             $email = $cr->getUser()->getSwiftEmail();
             if ($email) {
                 $tos[] = $email;
             }
         }
     }
     if ($tos) {
         $subject = 'Ticket-Notification';
         $body = "A new ticket about the following subject has been created:\n\n";
         $body .= "   Topic: " . $this->getKindName() . "\n";
         if ($this->getCampaignId()) {
             $body .= "Campaign: " . $this->getCampaign()->getName() . "\n";
         }
         if ($this->getPetitionId()) {
             $body .= "  Action: " . $this->getPetition()->getName() . "\n";
         }
         if ($this->getWidgetId()) {
             $body .= "  Widget: " . $this->getWidgetId() . "\n";
         }
         if ($this->getFromId()) {
             $body .= "    User: "******"\n";
         }
         $body .= "\n\n" . sfContext::getInstance()->getRouting()->generate('dashboard', array(), true);
         foreach ($tos as $to) {
             UtilMail::send(null, null, $to, $subject, $body);
         }
     }
 }
コード例 #2
0
 public function executeMembers()
 {
     $this->petition_rights_list = PetitionRightsTable::getInstance()->queryByPetition($this->petition)->execute();
     $this->admin = $this->petition->isMemberEditable($this->getGuardUser());
     if (isset($this->no_admin) && $this->no_admin) {
         $this->admin = false;
     }
     $this->csrf_token = UtilCSRF::gen('action_members');
     $this->become_admin = !$this->getGuardUser()->isPetitionAdmin($this->petition) && $this->petition->getCampaign()->getBecomePetitionAdmin();
     if ($this->become_admin) {
         $this->csrf_token_admin = UtilCSRF::gen('action_join_admin');
     }
 }
コード例 #3
0
 protected function joinPetitionAdmin(Ticket $ticket)
 {
     $pr = PetitionRightsTable::getInstance()->queryByPetitionAndUser($ticket->getPetition(), $ticket->getFrom())->fetchOne();
     if ($pr) {
         /* @var $pr PetitionRights */
         $pr->setAdmin(1);
         $pr->save();
     }
 }
コード例 #4
0
 public function executeEditMembers(sfWebRequest $request)
 {
     $this->ajax()->setAlertTarget('#petition_members', 'after');
     $petition = PetitionTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin());
     /* @var $petition Petition */
     if (!$petition) {
         return $this->ajax()->alert('Action not found', 'Error')->render();
     }
     if (!$petition->isMemberEditable($this->getGuardUser())) {
         return $this->ajax()->alert('You are not admin', 'Error')->render();
     }
     if ($request->getPostParameter('csrf_token') !== UtilCSRF::gen('action_members')) {
         return $this->ajax()->alert('CSRF Attack detected, please relogin.', 'Error')->render();
     }
     $ids = $request->getPostParameter('ids');
     $method = $request->getPostParameter('method');
     if (!in_array($method, array('block', 'member', 'admin'))) {
         return $this->ajax()->alert('Something is wrong.', 'Error')->render();
     }
     $self = false;
     if (is_array($ids)) {
         foreach (PetitionRightsTable::getInstance()->queryByPetitionAndUsers($petition->getId(), $ids)->execute() as $petition_rights) {
             /* @var $petition_rights PetitionRights */
             if ($this->isSelfUser($petition_rights->getUserId())) {
                 $self = true;
                 continue;
             }
             if ($method === 'block') {
                 $petition_rights->setActive(0);
             } elseif ($method === 'member') {
                 $petition_rights->setActive(1);
                 $petition_rights->setMember(1);
                 $petition_rights->setAdmin(0);
             } elseif ($method === 'admin') {
                 $petition_rights->setActive(1);
                 $petition_rights->setMember(1);
                 $petition_rights->setAdmin(1);
             }
             $petition_rights->save();
         }
     }
     $this->ajax()->replaceWithComponent('#petition_members', 'd_action', 'members', array('petition' => $petition));
     if ($self) {
         $this->ajax()->alert('You can not edit yourself.', 'Error');
     }
     return $this->ajax()->render();
 }
コード例 #5
0
 /**
  *
  * @param Petition $petition
  * @return PetitionRights
  */
 public function getRightsByPetition(Petition $petition)
 {
     if (array_key_exists($petition->getId(), $this->pr_cache)) {
         return $this->pr_cache[$petition->getId()];
     }
     return $this->pr_cache[$petition->getId()] = PetitionRightsTable::getInstance()->queryByPetitionAndUser($petition, $this)->fetchOne();
 }
コード例 #6
0
 public function executeEdit(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     if (is_numeric($id)) {
         $user = sfGuardUserTable::getInstance()->find($id);
         /* @var $user sfGuardUser */
         if (!$user) {
             return $this->notFound();
         }
     } else {
         $user = new sfGuardUser();
         $user->setIsActive(false);
     }
     if (!$this->getGuardUser()->getIsSuperAdmin() && $user->getIsSuperAdmin()) {
         $this->noAccess();
     }
     if ($user->isNew()) {
         $this->form = new UserNewForm($user);
     } else {
         $this->form = new UserForm($user);
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $con = sfGuardUserTable::getInstance()->getConnection();
             $con->beginTransaction();
             try {
                 $this->form->updateGroupsList($this->form->getValues());
                 $user = $this->form->updateObject();
                 $user->setUsername($user->getEmailAddress());
                 if ($user->isNew()) {
                     $user->setValidationKind(sfGuardUserTable::VALIDATION_KIND_BACKEND_LINK);
                     $user->randomValidationCode();
                     $user->save();
                     $subject = 'validate activation';
                     $body = "#VALIDATION-URL#";
                     $store = StoreTable::getInstance()->findByKeyAndLanguageWithFallback(StoreTable::NEW_USER_ADMIN_MAIL, $user->getLanguageId());
                     if ($store) {
                         $subject = $store->getField('subject');
                         $body = $store->getField('body');
                     }
                     $subst = array('#VALIDATION-URL#' => $this->generateUrl('user_validation', array('id' => $user->getId(), 'code' => $user->getValidationCode()), true), '#USER-NAME#' => $user->getFullName());
                     UtilMail::send(null, null, $user->getEmailAddress(), $subject, $body, null, $subst);
                 } else {
                     $user->save();
                 }
                 $con->commit();
             } catch (Exception $e) {
                 $con->rollback();
                 throw $e;
             }
             return $this->ajax()->redirectRotue('user_idx')->render();
         } else {
             return $this->ajax()->form($this->form)->render();
         }
     }
     if (!$user->isNew()) {
         $this->campaign_rights_list = CampaignRightsTable::getInstance()->queryByUser($user)->execute();
         $this->petition_rights_list = PetitionRightsTable::getInstance()->queryByUser($user)->execute();
     }
 }