Exemplo n.º 1
0
 function index()
 {
     $mcontacts = new Model_Contacts();
     $groups = $mcontacts->getGroups();
     $fields = $mcontacts->getContactFields();
     $msg = null;
     if (isset($this->args[0])) {
         if ($this->args[0] == "add") {
             $this->view->setTitle("Новый контакт");
             if (isset($this->post["submit"])) {
                 $mcontacts->addContact($this->post);
                 $msg = "Контакт сохранён!";
             }
             if (isset($this->get["email"])) {
                 $email = $this->get["email"];
             } else {
                 $email = null;
             }
             $this->view->contacts_addcontact(array("msg" => $msg, "email" => $email, "groups" => $groups, "post" => $this->post, "fields" => $fields));
         } elseif ($this->args[0] == "edit") {
             $this->view->setTitle("Правка контакта");
             if (isset($this->post["submit"])) {
                 $mcontacts->editContact($this->post);
                 $msg = "Контакт сохранён!";
                 $post = $mcontacts->getContact($this->post["email"]);
                 $email = $this->post["email"];
             } else {
                 $post = $mcontacts->getContact($this->get["email"]);
                 $email = $this->get["email"];
             }
             $this->view->contacts_editcontact(array("msg" => $msg, "email" => $email, "groups" => $groups, "post" => $post, "fields" => $fields));
         }
     } else {
         $this->view->setTitle("Контакты");
         if (isset($this->get["groups"])) {
             $contacts = $mcontacts->getContacts($this->get["groups"]);
             $this->view->contacts_groupcontacts(array("contacts" => $contacts));
         } else {
             $contacts = $mcontacts->getContacts();
             $this->view->contacts_contacts(array("groups" => $groups, "contacts" => $contacts));
         }
     }
 }
Exemplo n.º 2
0
 private function getForm()
 {
     $request = $this->getRequest();
     $id = $request->getQuery('id');
     $info = Model_Contacts::getContact($id);
     if (!$info) {
         $url = '';
         if ($this->getRequest()->getQuery('page')) {
             $url = '?page=' . $this->getRequest()->getQuery('page');
         }
         $this->redirect($this->getRequest()->getBaseUrl() . $this->getRequest()->getModule() . '/contacts/' . $url);
     }
     $this->view->page_num = $this->getRequest()->getRequest('page', 1);
     $this->view->info = $info;
     if ($request->isPost()) {
         $this->view->answer = $request->getPost('answer');
     } else {
         $this->view->answer = $info['answer'];
     }
 }