Esempio n. 1
0
 function getAllProfileTemplates()
 {
     $db = AbstractDb::getObject();
     $retval = array();
     $profile_template_rows = null;
     $sql = "SELECT profile_template_id FROM network_has_profile_templates WHERE network_id='{$this->_id}'";
     $db->execSql($sql, $profile_template_rows, false);
     if ($profile_template_rows != null) {
         foreach ($profile_template_rows as $profile_template_row) {
             $retval[] = ProfileTemplate::getObject($profile_template_row['profile_template_id']);
         }
     }
     return $retval;
 }
 /**
  * This method will create a ProfileTemplateField based on the content type filter specified
  *
  * @param string $user_prefix                A identifier provided by the programmer to
  *                                           recognise it's generated form
  * @param string $profile_template              Must be present
  *
  * @return object The ProfileTemplateField object, or null if the user didn't create one
  * @static
  */
 public static function processCreateFieldUI($user_prefix, ProfileTemplate $profile_template)
 {
     $db = AbstractDb::getObject();
     // Init values
     $profile_template_field_object = null;
     $max_display_order_row = null;
     $name = "get_new_profile_template_field_{$user_prefix}_add";
     if (!empty($_REQUEST[$name])) {
         /* Get the display order to add the ProfileTemplateField at the end */
         $sql = "SELECT MAX(display_order) as max_display_order FROM profile_template_fields WHERE profile_template_id = '" . $profile_template->getId() . "'";
         $db->execSqlUniqueRes($sql, $max_display_order_row, false);
         $display_order = $max_display_order_row['max_display_order'] + 1;
         $profile_template_field_id = get_guid();
         $sql = "INSERT INTO profile_template_fields (profile_template_field_id, profile_template_id, display_order) VALUES ('{$profile_template_field_id}', '{$profile_template->getId()}', {$display_order});";
         if (!$db->execSqlUpdate($sql, false)) {
             throw new Exception(_('Unable to insert new content into database!'));
         }
         $profile_template_field_object = self::getObject($profile_template_field_id);
         $name = "get_new_profile_template_field_{$user_prefix}_content_type_filter";
         $content_type_filter_ui_result = FormSelectGenerator::getResult($name, null);
         if (empty($content_type_filter_ui_result)) {
             throw new exception("Unable to retrieve the content type filter to associate with the new field");
         }
         $content_type_filter = ContentTypeFilter::getObject($content_type_filter_ui_result);
         $profile_template_field_object->replaceContentTypeFilter($content_type_filter);
     }
     return $profile_template_field_object;
 }
Esempio n. 3
0
 /** Get the selected ProfileTemplate object
  * @param $user_prefix A identifier provided by the programmer to recognise it's generated form
  * @return the ProfileTemplate object or null
  */
 static function processLinkedProfileTemplateUI($user_prefix, $link_table, $link_table_obj_key_col, $link_table_obj_key)
 {
     $db = AbstractDb::getObject();
     $link_table = $db->escapeString($link_table);
     $link_table_obj_key_col = $db->escapeString($link_table_obj_key_col);
     $link_table_obj_key = $db->escapeString($link_table_obj_key);
     // Profile templates already linked
     $current_content_sql = "SELECT * FROM {$link_table} WHERE {$link_table_obj_key_col}='{$link_table_obj_key}'";
     $rows = null;
     $db->execSql($current_content_sql, $rows, false);
     if ($rows) {
         foreach ($rows as $row) {
             $profile_template = ProfileTemplate::getObject($row['profile_template_id']);
             $profile_template_id = $db->escapeString($profile_template->getId());
             $name = "{$user_prefix}_" . $profile_template->GetId() . "_erase";
             if (!empty($_REQUEST[$name])) {
                 $sql = "DELETE FROM {$link_table} WHERE {$link_table_obj_key_col}='{$link_table_obj_key}' AND profile_template_id = '{$profile_template_id}';\n";
                 $db->execSqlUpdate($sql, false);
             }
         }
     }
     // Link an existing profile template
     $name = "{$user_prefix}_new_existing_add";
     if (!empty($_REQUEST[$name])) {
         $name = "{$user_prefix}_new_existing";
         $profile_template = ProfileTemplate::processSelectProfileTemplateUI($name);
         if ($profile_template) {
             $profile_template_id = $db->escapeString($profile_template->getId());
             $sql = "INSERT INTO {$link_table} (profile_template_id, {$link_table_obj_key_col}) VALUES ('{$profile_template_id}', '{$link_table_obj_key}');\n";
             $db->execSqlUpdate($sql, false);
         }
     }
 }
Esempio n. 4
0
 public function processAdminUI()
 {
     $db = AbstractDb::getObject();
     $currentUser = self::getCurrentUser();
     if (Security::hasPermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) {
         /* Account status */
         $name = "user_" . $this->getId() . "_accountstatus";
         $status = FormSelectGenerator::getResult($name, null);
         $this->setAccountStatus($status);
     }
     if ($this == $currentUser || Security::requirePermission(Permission::P('NETWORK_PERM_EDIT_ANY_USER'), $this->getNetwork())) {
         /* Username */
         $name = "user_" . $this->getId() . "_username";
         $this->setUsername($_REQUEST[$name]);
         /* Change password */
         $nameOldpassword = "******" . $this->getId() . "_oldpassword";
         $nameNewpassword = "******" . $this->getId() . "_newpassword";
         $nameNewpasswordAgain = "user_" . $this->getId() . "_newpassword_again";
         if ($_REQUEST[$nameNewpassword] != null) {
             if ($this == $currentUser && $this->getPasswordHash() != User::passwordHash($_REQUEST[$nameOldpassword])) {
                 throw new Exception(_("Wrong password."));
             }
             if ($_REQUEST[$nameNewpassword] != $_REQUEST[$nameNewpasswordAgain]) {
                 throw new Exception(_("Passwords do not match."));
             }
             $this->setPassword($_REQUEST[$nameNewpassword]);
         }
         // Pretend there is only one
         $profiles = $this->getAllProfiles();
         if (!empty($profiles)) {
             $current_profile = $profiles[0];
             if ($current_profile != null) {
                 $current_profile->processAdminUI();
                 $name = "user_" . $this->getId() . "_delete_profile_" . $current_profile->getId();
                 if (!empty($_REQUEST[$name])) {
                     $errmsg = null;
                     $current_profile->delete($errmsg);
                 }
             }
         } else {
             $name = "user_" . $this->getId() . "_add_profile";
             if (!empty($_REQUEST[$name])) {
                 // Get the list of profile templates for the users' network
                 $profile_templates = ProfileTemplate::getAllProfileTemplates($this->getNetwork());
                 if (!empty($profile_templates)) {
                     // Create a blank profile and link it to the user
                     $current_profile = Profile::createNewObject(null, $profile_templates[0]);
                     $this->addProfile($current_profile);
                 }
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Retrieves the associated profile template
  *
  * @return ProfileTemplate object
  *
  * @access public
  */
 public function getTemplate()
 {
     $retval = ProfileTemplate::getObject($this->_row['profile_template_id']);
     return $retval;
 }