<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class Userprofilelock_IndexController extends Core_Controller_Action_Standard {

  public function lockAction() {

		$subject_id = $this->_getParam('id', null);
		$profilelock = $this->_getParam('profilelock', 0);

		// Get form
		if(empty($profilelock)) {
			$this->view->form = $form = new Userprofilelock_Form_Profilelock_Lock();
			$successMessage = "Your profile is locked successfully.";
		} else {
			$this->view->form = $form = new Userprofilelock_Form_Profilelock_Unlock();
			$successMessage = "Your profile is unlocked successfully.";
		}

		if (!$this->getRequest()->isPost() || !$form->isValid($this->getRequest()->getPost())) {
			return;
		}

		$user = Engine_Api::_()->getItem('user', $subject_id);
		$user->profilelock = !$profilelock;
		$user->save();

		$this->_forward('success', 'utility', 'core', array(
			'smoothboxClose' => true,
			'parentRefresh' => true,
			'messages' => array(Zend_Registry::get('Zend_Translate')->_($successMessage))
		));
  }
}
