Example #1
0
 /**
  * Create a new ProfileField in the database
  *
  * @param string $profile MANDATORY The profile this field belongs to
  * @param string $templateField MANDATORY The template this field is based on
  * @param string $id Optionnal The id to be given to the new Object. If
  *                             null, a new id will be assigned
  *
  * @return object The newly created object, or null if there was an
  *                error (an exception is also trown)
  */
 public static function createNewObject(Profile $profile = null, ProfileTemplateField $templateField = null, $id = null)
 {
     $db = AbstractDb::getObject();
     $profileId = $db->escapeString($profile->getId());
     $templateFieldId = $db->escapeString($templateField->getId());
     if (empty($id)) {
         $fieldId = get_guid();
     } else {
         $fieldId = $db->escapeString($id);
     }
     $sql = "INSERT INTO profile_fields (profile_id, profile_field_id, profile_template_field_id) VALUES ('{$profileId}', '{$fieldId}', '{$templateFieldId}');\n";
     if (!$db->execSqlUpdate($sql, false)) {
         throw new Exception(_('Unable to insert the new profile fields in the database!'));
     }
     return self::getObject($fieldId);
 }
 /**
  * Process admin interface of this object
  *
  * @return void
  */
 public function processAdminUI()
 {
     Security::requirePermission(Permission::P('SERVER_PERM_EDIT_PROFILE_TEMPLATES'), Server::getServer());
     require_once 'classes/User.php';
     $errmsg = "";
     // label
     $_name = "profile_template_" . $this->getId() . "_label";
     $this->setLabel($_REQUEST[$_name]);
     foreach ($this->getFields() as $field) {
         $name = "profile_template_" . $this->id . "_field_" . $field->GetId() . "_erase";
         if (!empty($_REQUEST[$name]) && $_REQUEST[$name] == true) {
             $field->delete($errmsg);
         } else {
             $field->processAdminUI();
         }
     }
     ProfileTemplateField::processCreateFieldUI("profile_template_{$this->id}_new_field", $this);
 }