Code Duplication    Length = 9-22 lines in 5 locations

main/inc/lib/events.lib.php 1 location

@@ 770-786 (lines=17) @@
767
     * @param string $event_type
768
     * @return array|bool
769
     */
770
    public static function get_events_by_user_and_type($user_id, $event_type)
771
    {
772
        $TABLETRACK_DEFAULT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
773
        $user_id = intval($user_id);
774
        $event_type = Database::escape_string($event_type);
775
776
        $sql = "SELECT * FROM $TABLETRACK_DEFAULT
777
                WHERE default_value_type = 'user_id' AND
778
                      default_value = $user_id AND
779
                      default_event_type = '$event_type'
780
                ORDER BY default_date ";
781
        $result = Database::query($sql);
782
        if ($result) {
783
            return Database::store_result($result, 'ASSOC');
784
        }
785
        return false;
786
    }
787
788
    /**
789
     * Save the new message for one event and for one language

main/inc/lib/usermanager.lib.php 1 location

@@ 1047-1068 (lines=22) @@
1044
     * @return int User id
1045
     * @assert ('0','---') === 0
1046
     */
1047
    public static function get_user_id_from_original_id($original_user_id_value, $original_user_id_name)
1048
    {
1049
        $t_uf = Database::get_main_table(TABLE_EXTRA_FIELD);
1050
        $t_ufv = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
1051
        $extraFieldType = EntityExtraField::USER_FIELD_TYPE;
1052
        $sql = "SELECT item_id as user_id
1053
                FROM $t_uf uf
1054
                INNER JOIN $t_ufv ufv
1055
                ON ufv.field_id=uf.id
1056
                WHERE
1057
                    variable='$original_user_id_name' AND
1058
                    value='$original_user_id_value' AND
1059
                    extra_field_type = $extraFieldType
1060
                ";
1061
        $res = Database::query($sql);
1062
        $row = Database::fetch_object($res);
1063
        if ($row) {
1064
            return $row->user_id;
1065
        } else {
1066
            return 0;
1067
        }
1068
    }
1069
1070
    /**
1071
     * Check if a username is available

main/inc/lib/api.lib.php 2 locations

@@ 4134-4146 (lines=13) @@
4131
 * @param   string  language name (the corresponding name of the language-folder in the filesystem)
4132
 * @return  int     id of the language
4133
 */
4134
function api_get_language_id($language)
4135
{
4136
    $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
4137
    if (empty($language)) {
4138
        return null;
4139
    }
4140
    $language = Database::escape_string($language);
4141
    $sql = "SELECT id FROM $tbl_language
4142
            WHERE dokeos_folder = '$language' LIMIT 1";
4143
    $result = Database::query($sql);
4144
    $row = Database::fetch_array($result);
4145
    return $row['id'];
4146
}
4147
4148
/**
4149
 * Gets language of the requested type for the current user. Types are :
@@ 5248-5256 (lines=9) @@
5245
 * @param int       Access URL
5246
 * @return boolean  False on failure, true on success
5247
 */
5248
function api_delete_category_settings_by_subkey($subkey, $access_url_id = 1) {
5249
    if (empty($subkey)) { return false; }
5250
    $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
5251
    $subkey = Database::escape_string($subkey);
5252
    $access_url_id = intval($access_url_id);
5253
    $sql = "DELETE FROM $t_cs WHERE subkey = '$subkey' AND access_url = $access_url_id";
5254
    $r = Database::query($sql);
5255
    return $r;
5256
}
5257
5258
/**
5259
 * Sets a platform configuration setting to a given value

main/inc/lib/TicketManager.php 1 location

@@ 149-160 (lines=12) @@
146
    /**
147
     * @param int $id
148
     */
149
    public static function deleteCategory($id)
150
    {
151
        $id = intval($id);
152
153
        $table = Database::get_main_table(TABLE_TICKET_TICKET);
154
        $sql = "UPDATE $table SET category_id = NULL WHERE category_id = $id";
155
        Database::query($sql);
156
157
        $table = Database::get_main_table(TABLE_TICKET_CATEGORY);
158
        $sql = "DELETE FROM $table WHERE id = $id";
159
        Database::query($sql);
160
    }
161
162
    /**
163
     * @param int $categoryId