Jump to content

[SOLVED] Custom page in BackOffice Ps1.2.5


ezakimak
 Share

Recommended Posts

Hii , can anybody give me hints on how to add a custom page in my BO, currently I have done this

- write my custom.php(1) and put it on my ../admin/tabs/

- in BO created a new tab from Tools->Tabs

- Filled in the fields

but it isnt working correctly.
I have to mention that I have another version of this custom.php on my shop's root directory and it is working but I wanted this to be callable from the BO, the only difference between these two files is the include statemets in it.

(1)this custom.php is a copy of password.php with the only difference that it resets password for all of my shop's customers

this is the code that isnt working, I would appreciate if you could give a hint on it:

<?php
include(PS_ADMIN_DIR.'/../config/config.inc.php');
if(intval(Configuration::get('PS_REWRITING_SETTINGS')) === 1)
   $rewrited_url = __PS_BASE_URI__;
include(PS_ADMIN_DIR.'/../header.php');
$smarty->display(_PS_THEME_DIR_.'passwordGenAll.tpl');


include_once(PS_ADMIN_DIR.'/../classesPEextentions/CustomerPE.php');
define('MIN_PASSWD_LENGTH', 8);
$errors = array();

   $customers = CustomerPE::getAllActiveCustomer();
   foreach($customers as $aCustomerRow)
   {          
       $customer=new Customer();
       $email = $aCustomerRow['email'];     
       $customer->getByemail($email);
       if (!Validate::isLoadedObject($customer))
           $errors[] = Tools::displayError('there is no account registered to this e-mail address');
       else
       {
           if ((strtotime($customer->last_passwd_gen.'+'.intval($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')).' minutes') - time()) > 0)
               $errors[] = Tools::displayError('You can regenerate your password only each').' '.intval($min_time).' '.Tools::displayError('minute(s)');
           else
           {
               $customer->passwd = Tools::encrypt($password = Tools::passwdGen(intval(MIN_PASSWD_LENGTH)));
               $customer->last_passwd_gen = date('Y-m-d H:i:s', time());
               if ($customer->update())
               {
                   Mail::Send(intval($cookie->id_lang), 'password', 'Your password', 
                   array('{email}' => $customer->email, 
                   '{lastname}' => $customer->lastname, 
                   '{firstname}' => $customer->firstname, 
                   '{passwd}' => $password), 
                   $customer->email, 
                   $customer->firstname.' '.$customer->lastname);
                   $smarty->assign(array('confirmation' => 1, 'email' => $customer->email));
               }
               else
                   $errors[] = Tools::displayError('error with your account and your new password cannot be sent to your e-mail; please report your problem using the contact form');
           }
       }
   }

$smarty->assign('errors', $errors);
Tools::safePostVars();
include(PS_ADMIN_DIR.'/../footer.php');

?>


and this is the code that is working:

<?php
include(dirname(__FILE__).'/config/config.inc.php');
if(intval(Configuration::get('PS_REWRITING_SETTINGS')) === 1)
   $rewrited_url = __PS_BASE_URI__;
include(dirname(__FILE__).'/header.php');
$smarty->display(_PS_THEME_DIR_.'passwordGenAll.tpl');


include_once(dirname(__FILE__).'/classesPEextentions/CustomerPE.php');
define('MIN_PASSWD_LENGTH', 8);
$errors = array();

   $customers = CustomerPE::getAllActiveCustomers();
   foreach($customers as $aCustomerRow)
   {          
       $customer=new Customer();
       $email = $aCustomerRow['email'];     
       $customer->getByemail($email);
       if (!Validate::isLoadedObject($customer))
           $errors[] = Tools::displayError('there is no account registered to this e-mail address');
       else
       {
           if ((strtotime($customer->last_passwd_gen.'+'.intval($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')).' minutes') - time()) > 0)
               $errors[] = Tools::displayError('You can regenerate your password only each').' '.intval($min_time).' '.Tools::displayError('minute(s)');
           else
           {
               $customer->passwd = Tools::encrypt($password = Tools::passwdGen(intval(MIN_PASSWD_LENGTH)));
               $customer->last_passwd_gen = date('Y-m-d H:i:s', time());
               if ($customer->update())
               {
                   Mail::Send(intval($cookie->id_lang), 'password', 'Your password', 
                   array('{email}' => $customer->email, 
                   '{lastname}' => $customer->lastname, 
                   '{firstname}' => $customer->firstname, 
                   '{passwd}' => $password), 
                   $customer->email, 
                   $customer->firstname.' '.$customer->lastname);
                   $smarty->assign(array('confirmation' => 1, 'email' => $customer->email));
               }
               else
                   $errors[] = Tools::displayError('error with your account and your new password cannot be sent to your e-mail; please report your problem using the contact form');
           }
       }
   }

$smarty->assign('errors', $errors);
Tools::safePostVars();
include(dirname(__FILE__).'/footer.php');

?>

Share this post


Link to post
Share on other sites

Hii , can anybody give me hints on how to add a custom page in my BO, currently I have done this

- write my custom.php(1) and put it on my ../admin/tabs/

- in BO created a new tab from Tools->Tabs

- Filled in the fields

but it isnt reseting the customers passwords.
I have to mention that I have another version of this custom.php on my shop's root directory and it is working but I wanted this to be callable from the BO, the only difference between these two files is the include statemets in it.

(1)this custom.php is a copy of password.php with the only difference that it resets password for all of my shop's customers



Just take a look at this file here and it will solve your problem.
<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');

class AdminEbay extends AdminTab
{

   public function display()
   {
       echo ''.$this->l('Shop Tools').'';
       echo '
'.$this->l('Several tools are available to manage your shop.').'';
       echo '
';
       echo '
'.$this->l('Please choose a tool by selecting a Tools sub-tab above.').'';
       echo '';
   }

}
?>

Share this post


Link to post
Share on other sites

Hello,

I worked out my code and come out with this , but from time to time it gives this error

Notice: Undefined variable: smarty in /var/www/vhosts/companyname.jp/httpdocs/store/escritorio/tabs/passwordForAllCustomers.php  on line 55

Fatal error: Call to a member function assign() on a non-object in /var/www/vhosts/companyname.jp/httpdocs/store/escritorio/tabs/passwordForAllCustomers.php on line 55 



these is my final code

//AdminPasswordGenAll.php
<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
include_once(PS_ADMIN_DIR.'/tabs/passwordForAllCustomers.php');

class AdminPasswordGenAll extends AdminTab
{
 public function __construct()
 {
     parent::__construct();
 }

 public function display()
 {
   $module = new passwordForAllCustomers;
   echo $module->getContent();
 }
}
?>


//passwordForAllCustomers.php
<?php
include_once(PS_ADMIN_DIR.'/../config/config.inc.php');
include_once(PS_ADMIN_DIR.'/../classesPEextentions/CustomerPE.php');    

class passwordForAllCustomers extends Module
{

   public function __construct()
   {
       $this->name = 'PasswordReset';
       $this->tab = 'Reset password for all Customers';
       $this->version = 1.0;
       $this->page = basename(__FILE__, '.php');
       parent::__construct();

       $this->displayName = $this->l('Reset password');
       $this->description = $this->l('Reset password!');
   }

   private function _postProceed()
   {
       $cookie = new Cookie('ps');
       if(Tools::isSubmit('submitResetAllPasswords'))
       {
           Tools::setCookieLanguage();
           Tools::switchLanguage();
           define('MIN_PASSWD_LENGTH', 8);
           $errors = array();
           $customers = CustomerPE::getOneCustomer();
           foreach($customers as $aCustomerRow)
           {          
               $customer=new Customer();
               $email = $aCustomerRow['email'];     
               $customer->getByemail($email);
               if (!Validate::isLoadedObject($customer))
                   $errors[] = Tools::displayError('there is no account registered to this e-mail address');
               else
               {
                   if ((strtotime($customer->last_passwd_gen.'+'.intval($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')).' minutes') - time()) > 0)
                           $errors[] = Tools::displayError('You can regenerate your password only each').' '.intval($min_time).' '.Tools::displayError('minute(s)');
                   else
                   {
                       $customer->passwd = Tools::encrypt($password = Tools::passwdGen(intval(MIN_PASSWD_LENGTH)));
                       $customer->last_passwd_gen = date('Y-m-d H:i:s', time());
                       if ($customer->update())
                       {
                           Mail::Send(intval($cookie->id_lang), 'password', 'Your password', 
                                       array('{email}' => $customer->email, 
                                             '{lastname}' => $customer->lastname, 
                                             '{firstname}' => $customer->firstname, 
                                             '{passwd}' => $password), 
                                             $customer->email, 
                                             $customer->firstname.' '.$customer->lastname);
                                             $smarty->assign(array('confirmation' => 1, 'email' => $customer->email));
                       }
                       else
                           $errors[] = Tools::displayError('error with your account and your new password cannot be sent to your e-mail; please report your problem using the contact form');
                       }
               }
           }        

       }
       return $cookie;
   }

   public function getContent()    
   {
       $html = '';
       $cookie = $this->_postProceed();
       $html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
'.$this->l('Reset Passwords').'';
       $html .= ''.$this->l('Press the button if you are sure ').' ';
       $html .= '


           <input type="submit" name="submitResetAllPasswords" value="'.$this->l('go reset').'" class="button" />


           </form>';
       $html .= $this->about();
       return $html;
   }

   public function about()
   {
       $html = '

'.$this->l('About').'
           Reset password for all customers'.'  ';
       return $html;
   }
}
?>



there is something that I am doing wrong when I deal with the smarty stuff, could anyone give another hint how to find what is going wrong

thanks for your help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More