/**
  * {@inheritDoc}
  */
 public function getModifyDate()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getModifyDate', array());
     return parent::getModifyDate();
 }
 public function addadminAction(Request $request)
 {
     /****** Admin session checking**********/
     $response = $this->checkAdmin($request->getSession());
     if ($response) {
         return $response;
     }
     /****** Super admin session checking**********/
     $superadmin = $this->supercheckAdmin($request->getSession());
     if ($superadmin) {
         return $superadmin;
     }
     $admin = new Admin();
     $em = $this->getDoctrine()->getManager();
     /******Submit form**********/
     if ($request->getMethod() == "POST") {
         $form = $request->get('form');
         /********Checking duplicate username***********/
         $query = $em->createQuery("SELECT p FROM MytripAdminBundle:Admin p WHERE  p.username = '******'username'] . "' ");
         $checkusername = $query->getResult();
         if (empty($checkusername)) {
             /********Checking duplicate email id***********/
             $emailquery = $em->createQuery("SELECT p FROM MytripAdminBundle:Admin p WHERE  p.email = '" . $form['email'] . "'");
             $checkemail = $emailquery->getResult();
             /********Save admin***********/
             if (empty($checkemail)) {
                 $password = sha1($form['password']);
                 $admin->setName($form['name']);
                 $admin->setPassword($password);
                 $admin->setUsername($form['username']);
                 $admin->setEmail($form['email']);
                 $admin->setCmcode($form['cmcode']);
                 $admin->setMobile($form['mobile']);
                 $admin->setStatus("Active");
                 $admin->setModifyDate(new \DateTime(date('Y-m-d H:i:s')));
                 $em->persist($admin);
                 $em->flush();
                 $emaillist = $em->getRepository('MytripAdminBundle:EmailList')->findOneBy(array('emailListId' => '2'));
                 $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '2', 'lan' => 'en'));
                 $link = $this->getRequest()->getSchemeAndHttpHost() . "/" . $this->container->get('router')->getContext()->getBaseUrl() . "/" . $this->generateUrl('mytrip_admin_homepage');
                 $message = str_replace(array('{name}', '{username}', '{password}', '{link}'), array($form['name'], $form['username'], $form['password'], $link), $emailcontent->getEmailContent());
                 /*******Admin Credentials send to new admin***********/
                 $this->mailsend($emaillist->getFromname(), $emaillist->getFromemail(), $form['email'], $emailcontent->getSubject(), $message, $emaillist->getCcmail());
                 $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Admin user successfully created</div>');
                 return $this->redirect($this->generateUrl('mytrip_admin_adminusers'));
             } else {
                 $this->get('session')->getFlashBag()->add('error', '<div class="error msg">Email id already exists</div>');
                 //return $this->redirect($this->generateUrl('mytrip_admin_adminusers'));
             }
         } else {
             $this->get('session')->getFlashBag()->add('error', '<div class="error msg">Username already exists</div>');
             //return $this->redirect($this->generateUrl('mytrip_admin_adminusers'));
         }
     }
     /********Add admin form**********/
     $addadmin = $this->createFormBuilder($admin, array('attr' => array('id' => 'myForm')))->add('username', 'text', array('label' => 'Username', 'attr' => array('class' => 'validate[required,minSize[5]]', 'value' => isset($_REQUEST['form']['username']) ? $_REQUEST['form']['username'] : '', 'size' => '50'), 'required' => false))->add('name', 'text', array('label' => 'Name', 'attr' => array('class' => 'validate[required]', 'value' => isset($_REQUEST['form']['name']) ? $_REQUEST['form']['name'] : '', 'size' => '50'), 'required' => false))->add('password', 'password', array('label' => 'Password', 'attr' => array('class' => 'validate[required]', 'value' => "", 'size' => '50'), 'required' => false))->add('email', 'text', array('label' => 'Email', 'attr' => array('class' => 'validate[required,custom[email]]', 'value' => isset($_REQUEST['form']['email']) ? $_REQUEST['form']['email'] : '', 'size' => '50'), 'required' => false))->add('cmcode', 'text', array('label' => 'Code', 'attr' => array('class' => 'validate[required,custom[integer]]', 'value' => isset($_REQUEST['form']['cmcode']) ? $_REQUEST['form']['cmcode'] : '', 'size' => '5'), 'required' => false))->add('mobile', 'text', array('label' => 'Mobile', 'attr' => array('class' => 'validate[required,custom[integer]]', 'value' => isset($_REQUEST['form']['mobile']) ? $_REQUEST['form']['mobile'] : '', 'size' => '39'), 'required' => false))->add('save', 'submit', array('attr' => array('class' => 'button gray'), 'label' => "Save"))->getForm();
     return $this->render('MytripAdminBundle:Default:addadmin.html.php', array('addadmin' => $addadmin->createView()));
 }