function action_save()
 {
     $isDuplicate = empty($_REQUEST['record']) && empty($_REQUEST['return_id']);
     // check if there are any modifications
     $modified = hasBeenModified($this->bean, array());
     if (!$isDuplicate && !$modified) {
         return;
         // skip save if this is not a duplicate and nothing been modified
     }
     //2.0 We determine to what catalog category belongs
     if (!empty($this->bean->relatedcategory_id)) {
         $category = new oqc_Category();
         if ($category->retrieve($this->bean->relatedcategory_id)) {
             $this->bean->catalog_id = $category->catalog_id;
         }
     }
     // save id of user that created the old version
     global $timedate;
     $dateCreated = $timedate->to_db($this->bean->date_entered);
     $createdById = $this->bean->created_by;
     $old_id = $this->begin_new_version();
     parent::action_save();
     $this->end_new_version($old_id);
     $this->initializeUniqueIdentifier();
     $this->save_packaged_products();
     $this->saveAttachedDocuments();
     $this->saveProductOptions();
     $this->saveImageWithResize();
     $this->updateRelatedProducts($old_id);
     //$GLOBALS['log']->error("Dates are: ". $this->bean->date_entered );
     // the new contract should have the same creator and creation date as the previous version, fix for #486
     if ($dateCreated) {
         $this->bean->date_entered = $dateCreated;
     }
     if ($createdById) {
         $this->bean->created_by = $createdById;
     }
     if (!isset($_POST['assigned_user_id'])) {
         $this->bean->assigned_user_id = $this->bean->created_by;
     }
     //2.1 set this only if it is not in $_POST
     parent::action_save();
 }
 function action_save()
 {
     // make duplicate create new costs and positions
     $isDuplicate = empty($_REQUEST['record']) && empty($_REQUEST['return_id']);
     // check if there are any modifications
     $modified = hasBeenModified($this->bean, array('finalcosts'));
     if (!$isDuplicate && !$modified) {
         return;
         // skip save if this is not a duplicate and nothing has nothing has been modified
     }
     if ($this->bean->enddate != $_REQUEST['enddate']) {
         $this->bean->already_notified = false;
         // notify user again because the enddate has changed.
     }
     // save id of user that created the old version
     global $timedate;
     $dateCreated = $timedate->to_db($this->bean->date_entered);
     $createdById = $this->bean->created_by;
     $old_id = $this->begin_new_version();
     parent::action_save();
     $this->end_new_version($old_id);
     // save related data. parent::action_save() had to be called once already (auditing).
     $this->saveCosts($isDuplicate);
     $this->savePositions($isDuplicate);
     $this->saveSVNumbers();
     $this->saveAttachedDocuments();
     //1.7.6
     // the new contract should have the same creator and creation date as the previous version, fix for #486
     if ($dateCreated) {
         $this->bean->date_entered = $dateCreated;
     }
     if ($createdById) {
         $this->bean->created_by = $createdById;
     }
     // workaround for #487: write id stored in created_by field into assigned_user_id field to make sure that searches similiar to 'only my items' work properly
     $this->bean->assigned_user_id = $this->bean->created_by;
     parent::action_save();
     $accountRelationName = 'accounts';
     $contactsRelationName = 'contacts';
     // make sure that the relations can be loaded
     if ($this->bean->load_relationship($accountRelationName) && $this->bean->load_relationship($contactsRelationName)) {
         if ($this->relationshipHasBeenChanged(new Account(), $accountRelationName, array('account_id'))) {
             // delete relationsships to accounts and contacts
             $this->removeAllFromRelationship(new Account(), $accountRelationName);
             // add the relationsships  again. this avoids duplicates and outdated data
             $this->bean->accounts->add($this->bean->account_id);
         }
         if ($this->relationshipHasBeenChanged(new Contact(), $contactsRelationName, array('clientcontact_id', 'technicalcontact_id'))) {
             // delete relationsships to accounts and contacts
             $this->removeAllFromRelationship(new Contact(), $contactsRelationName);
             // add the relationsships  again. this avoids duplicates and outdated data
             $this->bean->contacts->add($this->bean->clientcontact_id);
             $this->bean->contacts->add($this->bean->technicalcontact_id);
             // TODO add relationship to employee (contact_id)
         }
     }
 }