Esempio n. 1
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);
         }
     }
 }