view->headLink()->appendStylesheet('/css/profile/profile.css'); $this->view->headScript()->appendFile('/js/profile/sign-in.js'); $this->view->headScript()->appendFile('/js/profile/sign-up.js'); $this->_auth = Zend_Auth::getInstance(); $this->_params = $this->_getAllParams(); $this->_redirector = $this->_helper->getHelper('Redirector'); $this->_db = Zend_Db_Table::getDefaultAdapter(); $this->_auth = Zend_Auth::getInstance(); $this->_helper ->AjaxContext ->addActionContext('ajax', 'json') ->initContext('json'); $this->_helper ->AjaxContext ->addActionContext('statistics', 'json') ->initContext('json'); $this->_helper ->AjaxContext ->addActionContext('upload', 'json') ->initContext('json'); $this->_helper ->AjaxContext ->addActionContext('imageajax', 'json') ->initContext('json'); $this->_helper ->AjaxContext ->addActionContext('deleteimage', 'json') ->initContext('json'); $auth = Zend_Auth::getInstance(); /* $this->_helper ->AjaxContext ->addActionContext('deletefoto', 'html'); */ $authStorage = $auth->getStorage(); $this->_iduser = $authStorage->read()->id; $ownerInfo = new Profile_Model_DbTable_Users(); $this->_ownerinfo = $ownerInfo->getUserInfo($this->_iduser); $this->view->ownerInfo = $this->_ownerinfo; // if (file_exists('users/' . $this->_iduser)) { // $this->_images = '/users/' . $this->_iduser . '/i225.jpg'; // } else { // $this->_images = '/users/no-image/user_pic-68x68.png'; // } if ($this->_auth->getIdentity()->group_id == 3) { $this->_helper->redirector('index', 'index', 'dashboard'); } } public function indexAction() { //if ($this->_auth->hasIdentity()) { // $this->view->message = "Личный кабинет закрыт на ремонт, извините за неудобства"; //} // Zend_Debug::dump($this->_auth->getIdentity()); } public function newavatarAction() { $auth = Zend_Auth::getInstance(); $authStorage = $auth->getStorage(); $id =$auth->getIdentity()->id; $table = new Profile_Model_DbTable_Users(); $rowset = $table->find($id); $row = $rowset->current(); $request = $this->getRequest(); $form = new Profile_Form_Newavatar(); if ($request->isPost()) { if ( $form->isValid( $request->getPost() ) ) { //Function for recursive removal of a nonempty directory $dir="content/images/profile/$id"; if ($objs = glob($dir."/*")) { foreach($objs as $obj) { is_dir($obj) ? removeDirRec($obj) : unlink($obj); } } rmdir($dir); $file = $form->picture->getFileInfo(); $ext = split("[/\\.]", $file['picture']['name']); // $newName = $this->_iduser.".jpg"; $ran = time() ; $newName = "$ran.".$ext[count($ext)-1]; if (!is_dir('./content/images/profile/'.$id)) { mkdir("content/images/profile/$id", 0777); } $form->picture->addFilter('Rename', realpath(dirname('.')). DIRECTORY_SEPARATOR. 'content'. DIRECTORY_SEPARATOR. 'images'. DIRECTORY_SEPARATOR. 'profile'. DIRECTORY_SEPARATOR. $id. DIRECTORY_SEPARATOR. $newName); $picture = $form->getValue('picture'); $pic = "/content/images/profile/$id/$picture"; $pic1 = "content/images/profile/$id/$picture"; $pic2 = "content/images/profile/$id/n$picture"; copy("$pic1","$pic2"); $user = new Profile_Model_DbTable_Users(); $user->updateUserPicture($id, $pic); $db=Zend_Db_Table::getDefaultAdapter(); $sql='INSERT forum_User (Photo) VALUES ('.$pic.'")'; $db->query($sql); $db->query($sql); $form->picture->receive(); //Zend_Debug :: dump($this->_request->getParams()); // echo $Newname; //ZEND_DEBUG :: dump($ownerInfo['picture']); $this->_helper->redirector('index', 'index', 'profile'); } } $this->view->form=$form; } public function deleteAction() { $id=$this->_getParam($id); $picture = new Profile_Model_DbTable_Users($picture); $picture->delete(); $this->_helper->redirector('index', 'index', 'profile'); } public function editAction() { $auth = Zend_Auth::getInstance(); $authStorage = $auth->getStorage(); $id =$auth->getIdentity()->id; $this->view->title = "Edit Info"; $this->view->headTitle($this->view->title); $form = new Profile_Form_Edit(); $table = new Profile_Model_DbTable_Users(); $rowset = $table->find($id); $row = $rowset->current(); $birth = new Zend_Date($row->birthdate); $trimmed = $birth->toString('dd-MM-yyyy'); //$trimmed = trim($birth, " 00:00:0."); //$value = $form->getValue('birthdate'); //Zend_Debug :: dump($this->_request->getParams()); // echo $birth; // echo gettype($birth); // ZEND_DEBUG :: dump($row['birthdate']); $row['birthdate'] = $trimmed; $form->populate($row->toArray()); //$form->submit->setLabel('Save'); $this->view->form = $form; if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $name = $form->getValue('name'); $email = $form->getValue('email'); $birthdate = $form->getValue('birthdate'); $birthdate = new Zend_Date($birthdate); $job = $form->getValue('job'); $country = $form->getValue('country'); //$password=$form->getValue('password'); $password = sha1($form->getValue('password')); $repeatPassword=sha1($form->getValue('repeatPassword')); $user = new Profile_Model_DbTable_Users(); // $date=explode('-', $birthdate); // $date=sprintf('%s-%s-%s',$date[2],$date[1],$date[0]); $user->updateUserInfo($id, $name, $email,$birthdate->toString('yyyy-MM-dd'),$job,$country,$password,$repeatPassword); // Zend_Debug :: dump($this->_request->getParams()); // echo ($id); // echo ($date); // exit; $this->_helper->redirector('index'); } else { $form->populate($formData); } } else { $id = $this->_getParam('id', 0); if ($id > 0) { $user = new Profile_Model_DbTable_User(); $form->populate($user->getUserInfo($id)); } } $this->view->action = 'edit'; } public function editdiscribeAction() { $auth = Zend_Auth::getInstance(); $authStorage = $auth->getStorage(); $id =$auth->getIdentity()->id; $this->view->title = "Edit Info"; $this->view->headTitle($this->view->title); $form = new Profile_Form_EditDiscribe(); $table = new Profile_Model_DbTable_Users(); $rowset = $table->find($id); $row = $rowset->current(); $form->populate($row->toArray()); //$form->submit->setLabel('Save'); $this->view->form = $form; if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $about = $form->getValue('about'); $user = new Profile_Model_DbTable_Users(); $user->updateUserDiscribe($id, $about); $this->_helper->redirector('index'); } else { $form->populate($formData); } } else { $id = $this->_getParam('id', 0); if ($id > 0) { $user = new Profile_Model_DbTable_User(); $form->populate($user->getUserInfo($id)); } } $this->view->action = 'editdiscribe'; } }