Index: branches/5.2.x/units/gift_certificates/gift_certificates_eh.php =================================================================== diff -u -N -r14258 -r14569 --- branches/5.2.x/units/gift_certificates/gift_certificates_eh.php (.../gift_certificates_eh.php) (revision 14258) +++ branches/5.2.x/units/gift_certificates/gift_certificates_eh.php (.../gift_certificates_eh.php) (revision 14569) @@ -1,6 +1,6 @@ permMapping = array_merge($this->permMapping, $permissions); } - function OnApplyClone(&$event) - { - $item = &$event->getObject(); - $clone_count = $this->Application->GetVar('clone_items_count'); - $table = $this->Application->getUnitOption($event->Prefix, 'TableName'); - if ($clone_count && $clone_count>0){ - $this->Application->StoreVar('CoupLastCloneCount', $clone_count); - for ($i=0; $i<$clone_count; $i++) { - $this->SetNewCode($item); - - $item->SetField('Expiration_date', $this->Application->GetVar('clone_exp_date')); - $item->SetField('Expiration_time', $this->Application->GetVar('clone_exp_time')); - $item->NameCopy(); - $validated = $item->Create(); - - - } - } - - if ($validated){ - $this->finalizePopup($event); - }else{ - $event->redirect = false; - } - } - - function SetNewCode(&$item) - { - do{ - $new_code = $this->RandomCouponCode(10); - $exists = $this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'ProductsCoupons WHERE Code='.$this->Conn->qstr($new_code)); - if ($exists){ - $new_code = false; - } - } while (!$new_code); - - $item->SetDBField('Code', $new_code); - } - - function RandomCouponCode($size) - { - $rand_code = ""; - for ($i=0; $i<10; $i++){ - $is_letter = rand(0,1); - if ($is_letter){ - $rand_char = chr(rand(65,90)); - }else{ - $rand_char = rand(0,9); - } - $rand_code .= $rand_char; - } - return $rand_code; - } - /** * Enter description here... * @@ -133,12 +79,13 @@ { parent::OnPreCreate($event); - $object = &$event->getObject(); + $object =& $event->getObject(); + /* @var $object kDBItem */ + $exp_date = adodb_mktime(); - $default_duration = $this->Application->ConfigValue('Comm_DefaultCouponDuration'); - - if ($default_duration && $default_duration > 0){ + + if ($default_duration){ $exp_date += (int)$default_duration * 86400; } $object->SetDBField('Expiration_date', $exp_date);