예제 #1
0
 public function create($d = array())
 {
     $withoutConfirm = isset($d['withoutConfirm']) ? $d['withoutConfirm'] : false;
     $mainEngine = $this->getMainEngine();
     if ($mainEngine) {
         // Confirnation will be processed by subscribe engine, here it will be created in active state
         $withoutConfirm = true;
     }
     if (isset($d['email']) && !empty($d['email'])) {
         if (is_email($d['email'])) {
             $d['email'] = trim($d['email']);
             $params = array('email' => $d['email'], 'created' => dbCsp::timeToDate(), 'ip' => utilsCsp::getIP(), 'active' => $withoutConfirm ? 1 : 0, 'token' => md5($d['email'] . AUTH_KEY));
             if (isset($d['name']) && !empty($d['name'])) {
                 $params['name'] = $d['name'];
             }
             /*$defSystem = frameCsp::_()->getModule('options')->get('sub_synchronize_system') ;
             		switch($defSystem) {*/
             /*case 'aweber':
             		$listId = frameCsp::_()->getModule('options')->get('sub_aweber_selected_list');
             		$aweberModule = frameCsp::_()->getModule('aweber'); 
             		$params['listId'] = $listId;
             		if($aweberModule->createNewAweberSubscriber($params)){
             			return true;
             		}else{
             			$this->pushError( langCsp::_($aweberModule->getErrors()) );
             			return false;
             		}
             		break;*/
             //default:
             if (!frameCsp::_()->getTable('subscribers')->exists($d['email'], 'email')) {
                 if (frameCsp::_()->getTable('subscribers')->insert($params)) {
                     if ($mainEngine) {
                         $mainEngine->subscribe($params);
                     }
                     $this->processEnginesSubscribe($params, $mainEngine);
                     if (!$withoutConfirm) {
                         $this->sendConfirmEmail($d['email']);
                     }
                     return true;
                 } else {
                     $this->pushError(langCsp::_('Error insert email to database'));
                 }
             } else {
                 $this->pushError(langCsp::_('You are already subscribed'));
             }
             /*break;
             		}*/
         } else {
             $this->pushError(langCsp::_('Invalid email'));
         }
     } else {
         $this->pushError(langCsp::_('Please enter email'));
     }
     return false;
 }
예제 #2
0
 /**
  * Prepare data before send it to database
  */
 public function prepareInput($d = array())
 {
     $ignore = isset($d['ignore']) ? $d['ignore'] : array();
     foreach ($this->_fields as $key => $f) {
         if ($f->type == 'tinyint') {
             if ($d[$key] == 'true') {
                 $d[$key] = 1;
             }
             if (empty($d[$key]) && !in_array($key, $ignore)) {
                 $d[$key] = 0;
             }
         }
         if ($f->type == 'date') {
             if (empty($d[$key]) && !in_array($key, $ignore)) {
                 $d[$key] = '0000-00-00';
             } elseif (!empty($d[$key])) {
                 $d[$key] = dbCsp::timeToDate($d[$key]);
             }
         }
     }
     $d[$this->_id] = isset($d[$this->_id]) ? intval($d[$this->_id]) : 0;
     return $d;
 }