コード例 #1
0
ファイル: element_set_ranks.php プロジェクト: donseba/Piwigo
/**
 * save the rank depending on given images order
 *
 * The list of ordered images id is supposed to be in the same parent
 * category
 *
 * @param array categories
 * @return void
 */
function save_images_order($category_id, $images)
{
    $current_rank = 0;
    $datas = array();
    foreach ($images as $id) {
        $datas[] = array('category_id' => $category_id, 'image_id' => $id, 'rank' => ++$current_rank);
    }
    $fields = array('primary' => array('image_id', 'category_id'), 'update' => array('rank'));
    mass_updates(IMAGE_CATEGORY_TABLE, $fields, $datas);
}
コード例 #2
0
function save_upload_form_config($data, &$errors = array(), &$form_errors = array())
{
    if (!is_array($data) or empty($data)) {
        return false;
    }
    $upload_form_config = get_upload_form_config();
    $updates = array();
    foreach ($data as $field => $value) {
        if (!isset($upload_form_config[$field])) {
            continue;
        }
        if (is_bool($upload_form_config[$field]['default'])) {
            if (isset($value)) {
                $value = true;
            } else {
                $value = false;
            }
            $updates[] = array('param' => $field, 'value' => boolean_to_string($value));
        } elseif ($upload_form_config[$field]['can_be_null'] and empty($value)) {
            $updates[] = array('param' => $field, 'value' => 'false');
        } else {
            $min = $upload_form_config[$field]['min'];
            $max = $upload_form_config[$field]['max'];
            $pattern = $upload_form_config[$field]['pattern'];
            if (preg_match($pattern, $value) and $value >= $min and $value <= $max) {
                $updates[] = array('param' => $field, 'value' => $value);
            } else {
                $errors[] = sprintf($upload_form_config[$field]['error_message'], $min, $max);
                $form_errors[$field] = '[' . $min . ' .. ' . $max . ']';
            }
        }
    }
    if (count($errors) == 0) {
        mass_updates(CONFIG_TABLE, array('primary' => array('param'), 'update' => array('value')), $updates);
        return true;
    }
    return false;
}
コード例 #3
0
ファイル: cat_list.php プロジェクト: lcorbasson/Piwigo
/**
 * save the rank depending on given categories order
 *
 * The list of ordered categories id is supposed to be in the same parent
 * category
 *
 * @param array categories
 * @return void
 */
function save_categories_order($categories)
{
    $current_rank_for_id_uppercat = array();
    $current_rank = 0;
    $datas = array();
    foreach ($categories as $category) {
        if (is_array($category)) {
            $id = $category['id'];
            $id_uppercat = $category['id_uppercat'];
            if (!isset($current_rank_for_id_uppercat[$id_uppercat])) {
                $current_rank_for_id_uppercat[$id_uppercat] = 0;
            }
            $current_rank = ++$current_rank_for_id_uppercat[$id_uppercat];
        } else {
            $id = $category;
            $current_rank++;
        }
        $datas[] = array('id' => $id, 'rank' => $current_rank);
    }
    $fields = array('primary' => array('id'), 'update' => array('rank'));
    mass_updates(CATEGORIES_TABLE, $fields, $datas);
    update_global_rank();
}
コード例 #4
0
/**
 * Sync all metadata of a list of images.
 * Metadata are fetched from original files and saved in database.
 *
 * @param int[] $ids
 */
function sync_metadata($ids)
{
    global $conf;
    if (!defined('CURRENT_DATE')) {
        define('CURRENT_DATE', date('Y-m-d'));
    }
    $datas = array();
    $tags_of = array();
    $query = '
SELECT id, path, representative_ext
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (
' . wordwrap(implode(', ', $ids), 160, "\n") . '
)
;';
    $result = pwg_query($query);
    while ($data = pwg_db_fetch_assoc($result)) {
        $data = get_sync_metadata($data);
        if ($data === false) {
            continue;
        }
        $id = $data['id'];
        foreach (array('keywords', 'tags') as $key) {
            if (isset($data[$key])) {
                if (!isset($tags_of[$id])) {
                    $tags_of[$id] = array();
                }
                foreach (explode(',', $data[$key]) as $tag_name) {
                    $tags_of[$id][] = tag_id_from_tag_name($tag_name);
                }
            }
        }
        $data['date_metadata_update'] = CURRENT_DATE;
        $datas[] = $data;
    }
    if (count($datas) > 0) {
        $update_fields = get_sync_metadata_attributes();
        $update_fields[] = 'date_metadata_update';
        $update_fields = array_diff($update_fields, array('tags', 'keywords'));
        mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => $update_fields), $datas, MASS_UPDATES_SKIP_EMPTY);
    }
    set_tags_of($tags_of);
}
コード例 #5
0
ファイル: functions.php プロジェクト: lcorbasson/Piwigo
/**
 * Updates categories.uppercats field based on categories.id + categories.id_uppercat
 */
function update_uppercats()
{
    $query = '
SELECT id, id_uppercat, uppercats
  FROM ' . CATEGORIES_TABLE . '
;';
    $cat_map = query2array($query, 'id');
    $datas = array();
    foreach ($cat_map as $id => $cat) {
        $upper_list = array();
        $uppercat = $id;
        while ($uppercat) {
            $upper_list[] = $uppercat;
            $uppercat = $cat_map[$uppercat]['id_uppercat'];
        }
        $new_uppercats = implode(',', array_reverse($upper_list));
        if ($new_uppercats != $cat['uppercats']) {
            $datas[] = array('id' => $id, 'uppercats' => $new_uppercats);
        }
    }
    $fields = array('primary' => array('id'), 'update' => array('uppercats'));
    mass_updates(CATEGORIES_TABLE, $fields, $datas);
}
コード例 #6
0
ファイル: stats.php プロジェクト: lcorbasson/Piwigo
                }
            }
        }
        if (isset($need_update[$key])) {
            $row['nb_pages'] += $need_update[$key];
            $updates[] = $row;
            unset($need_update[$key]);
        }
    }
}
foreach ($need_update as $time_key => $nb_pages) {
    $time_tokens = explode('-', $time_key);
    $inserts[] = array('year' => $time_tokens[0], 'month' => @$time_tokens[1], 'day' => @$time_tokens[2], 'hour' => @$time_tokens[3], 'nb_pages' => $nb_pages);
}
if (count($updates) > 0) {
    mass_updates(HISTORY_SUMMARY_TABLE, array('primary' => array('year', 'month', 'day', 'hour'), 'update' => array('nb_pages')), $updates);
}
if (count($inserts) > 0) {
    mass_inserts(HISTORY_SUMMARY_TABLE, array_keys($inserts[0]), $inserts);
}
if ($max_id != 0) {
    $query = '
UPDATE ' . HISTORY_TABLE . '
  SET summarized = \'true\'
  WHERE summarized = \'false\'
    AND id <= ' . $max_id . '
;';
    pwg_query($query);
}
// +-----------------------------------------------------------------------+
// | Page parameters check                                                 |
コード例 #7
0
/**
 * API method
 * Returns a list of categories
 * @param mixed[] $params
 *    @option int cat_id (optional)
 *    @option bool recursive
 *    @option bool public
 *    @option bool tree_output
 *    @option bool fullname
 */
function ws_categories_getList($params, &$service)
{
    global $user, $conf;
    $where = array('1=1');
    $join_type = 'INNER';
    $join_user = $user['id'];
    if (!$params['recursive']) {
        if ($params['cat_id'] > 0) {
            $where[] = '(
        id_uppercat = ' . (int) $params['cat_id'] . '
        OR id=' . (int) $params['cat_id'] . '
      )';
        } else {
            $where[] = 'id_uppercat IS NULL';
        }
    } else {
        if ($params['cat_id'] > 0) {
            $where[] = 'uppercats ' . DB_REGEX_OPERATOR . ' \'(^|,)' . (int) $params['cat_id'] . '(,|$)\'';
        }
    }
    if ($params['public']) {
        $where[] = 'status = "public"';
        $where[] = 'visible = "true"';
        $join_user = $conf['guest_id'];
    } else {
        if (is_admin()) {
            // in this very specific case, we don't want to hide empty
            // categories. Function calculate_permissions will only return
            // categories that are either locked or private and not permitted
            //
            // calculate_permissions does not consider empty categories as forbidden
            $forbidden_categories = calculate_permissions($user['id'], $user['status']);
            $where[] = 'id NOT IN (' . $forbidden_categories . ')';
            $join_type = 'LEFT';
        }
    }
    $query = '
SELECT
    id, name, comment, permalink,
    uppercats, global_rank, id_uppercat,
    nb_images, count_images AS total_nb_images,
    representative_picture_id, user_representative_picture_id, count_images, count_categories,
    date_last, max_date_last, count_categories AS nb_categories
  FROM ' . CATEGORIES_TABLE . '
    ' . $join_type . ' JOIN ' . USER_CACHE_CATEGORIES_TABLE . '
    ON id=cat_id AND user_id=' . $join_user . '
  WHERE ' . implode("\n    AND ", $where) . '
;';
    $result = pwg_query($query);
    // management of the album thumbnail -- starts here
    $image_ids = array();
    $categories = array();
    $user_representative_updates_for = array();
    // management of the album thumbnail -- stops here
    $cats = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        $row['url'] = make_index_url(array('category' => $row));
        foreach (array('id', 'nb_images', 'total_nb_images', 'nb_categories') as $key) {
            $row[$key] = (int) $row[$key];
        }
        if ($params['fullname']) {
            $row['name'] = strip_tags(get_cat_display_name_cache($row['uppercats'], null));
        } else {
            $row['name'] = strip_tags(trigger_change('render_category_name', $row['name'], 'ws_categories_getList'));
        }
        $row['comment'] = strip_tags(trigger_change('render_category_description', $row['comment'], 'ws_categories_getList'));
        // management of the album thumbnail -- starts here
        //
        // on branch 2.3, the algorithm is duplicated from
        // include/category_cats, but we should use a common code for Piwigo 2.4
        //
        // warning : if the API method is called with $params['public'], the
        // album thumbnail may be not accurate. The thumbnail can be viewed by
        // the connected user, but maybe not by the guest. Changing the
        // filtering method would be too complicated for now. We will simply
        // avoid to persist the user_representative_picture_id in the database
        // if $params['public']
        if (!empty($row['user_representative_picture_id'])) {
            $image_id = $row['user_representative_picture_id'];
        } else {
            if (!empty($row['representative_picture_id'])) {
                // if a representative picture is set, it has priority
                $image_id = $row['representative_picture_id'];
            } else {
                if ($conf['allow_random_representative']) {
                    // searching a random representant among elements in sub-categories
                    $image_id = get_random_image_in_category($row);
                } else {
                    // searching a random representant among representant of sub-categories
                    if ($row['count_categories'] > 0 and $row['count_images'] > 0) {
                        $query = '
SELECT representative_picture_id
  FROM ' . CATEGORIES_TABLE . '
    INNER JOIN ' . USER_CACHE_CATEGORIES_TABLE . '
    ON id=cat_id AND user_id=' . $user['id'] . '
  WHERE uppercats LIKE \'' . $row['uppercats'] . ',%\'
    AND representative_picture_id IS NOT NULL
        ' . get_sql_condition_FandF(array('visible_categories' => 'id'), "\n  AND") . '
  ORDER BY ' . DB_RANDOM_FUNCTION . '()
  LIMIT 1
;';
                        $subresult = pwg_query($query);
                        if (pwg_db_num_rows($subresult) > 0) {
                            list($image_id) = pwg_db_fetch_row($subresult);
                        }
                    }
                }
            }
        }
        if (isset($image_id)) {
            if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) {
                $user_representative_updates_for[$row['id']] = $image_id;
            }
            $row['representative_picture_id'] = $image_id;
            $image_ids[] = $image_id;
            $categories[] = $row;
        }
        unset($image_id);
        // management of the album thumbnail -- stops here
        $cats[] = $row;
    }
    usort($cats, 'global_rank_compare');
    // management of the album thumbnail -- starts here
    if (count($categories) > 0) {
        $thumbnail_src_of = array();
        $new_image_ids = array();
        $query = '
SELECT id, path, representative_ext, level
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $image_ids) . ')
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            if ($row['level'] <= $user['level']) {
                $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row);
            } else {
                // problem: we must not display the thumbnail of a photo which has a
                // higher privacy level than user privacy level
                //
                // * what is the represented category?
                // * find a random photo matching user permissions
                // * register it at user_representative_picture_id
                // * set it as the representative_picture_id for the category
                foreach ($categories as &$category) {
                    if ($row['id'] == $category['representative_picture_id']) {
                        // searching a random representant among elements in sub-categories
                        $image_id = get_random_image_in_category($category);
                        if (isset($image_id) and !in_array($image_id, $image_ids)) {
                            $new_image_ids[] = $image_id;
                        }
                        if ($conf['representative_cache_on_level']) {
                            $user_representative_updates_for[$category['id']] = $image_id;
                        }
                        $category['representative_picture_id'] = $image_id;
                    }
                }
                unset($category);
            }
        }
        if (count($new_image_ids) > 0) {
            $query = '
SELECT id, path, representative_ext
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $new_image_ids) . ')
;';
            $result = pwg_query($query);
            while ($row = pwg_db_fetch_assoc($result)) {
                $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row);
            }
        }
    }
    // compared to code in include/category_cats, we only persist the new
    // user_representative if we have used $user['id'] and not the guest id,
    // or else the real guest may see thumbnail that he should not
    if (!$params['public'] and count($user_representative_updates_for)) {
        $updates = array();
        foreach ($user_representative_updates_for as $cat_id => $image_id) {
            $updates[] = array('user_id' => $user['id'], 'cat_id' => $cat_id, 'user_representative_picture_id' => $image_id);
        }
        mass_updates(USER_CACHE_CATEGORIES_TABLE, array('primary' => array('user_id', 'cat_id'), 'update' => array('user_representative_picture_id')), $updates);
    }
    foreach ($cats as &$cat) {
        foreach ($categories as $category) {
            if ($category['id'] == $cat['id'] and isset($category['representative_picture_id'])) {
                $cat['tn_url'] = $thumbnail_src_of[$category['representative_picture_id']];
            }
        }
        // we don't want them in the output
        unset($cat['user_representative_picture_id'], $cat['count_images'], $cat['count_categories']);
    }
    unset($cat);
    // management of the album thumbnail -- stops here
    if ($params['tree_output']) {
        return categories_flatlist_to_tree($cats);
    }
    return array('categories' => new PwgNamedArray($cats, 'category', ws_std_get_category_xml_attributes()));
}
コード例 #8
0
ファイル: profile.php プロジェクト: lcorbasson/Piwigo
function save_profile_from_post($userdata, &$errors)
{
    global $conf, $page;
    $errors = array();
    if (!isset($_POST['validate'])) {
        return false;
    }
    $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']));
    if ($special_user) {
        unset($_POST['username'], $_POST['mail_address'], $_POST['password'], $_POST['use_new_pwd'], $_POST['passwordConf'], $_POST['theme'], $_POST['language']);
        $_POST['theme'] = get_default_theme();
        $_POST['language'] = get_default_language();
    }
    if (!defined('IN_ADMIN')) {
        unset($_POST['username']);
    }
    if ($conf['allow_user_customization'] or defined('IN_ADMIN')) {
        $int_pattern = '/^\\d+$/';
        if (empty($_POST['nb_image_page']) or !preg_match($int_pattern, $_POST['nb_image_page'])) {
            $errors[] = l10n('The number of photos per page must be a not null scalar');
        }
        // periods must be integer values, they represents number of days
        if (!preg_match($int_pattern, $_POST['recent_period']) or $_POST['recent_period'] < 0) {
            $errors[] = l10n('Recent period must be a positive integer value');
        }
        if (!in_array($_POST['language'], array_keys(get_languages()))) {
            die('Hacking attempt, incorrect language value');
        }
        if (!in_array($_POST['theme'], array_keys(get_pwg_themes()))) {
            die('Hacking attempt, incorrect theme value');
        }
    }
    if (isset($_POST['mail_address'])) {
        // if $_POST and $userdata have are same email
        // validate_mail_address allows, however, to check email
        $mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']);
        if (!empty($mail_error)) {
            $errors[] = $mail_error;
        }
    }
    if (!empty($_POST['use_new_pwd'])) {
        // password must be the same as its confirmation
        if ($_POST['use_new_pwd'] != $_POST['passwordConf']) {
            $errors[] = l10n('The passwords do not match');
        }
        if (!defined('IN_ADMIN')) {
            // changing password requires old password
            $query = '
  SELECT ' . $conf['user_fields']['password'] . ' AS password
    FROM ' . USERS_TABLE . '
    WHERE ' . $conf['user_fields']['id'] . ' = \'' . $userdata['id'] . '\'
  ;';
            list($current_password) = pwg_db_fetch_row(pwg_query($query));
            if (!$conf['password_verify']($_POST['password'], $current_password)) {
                $errors[] = l10n('Current password is wrong');
            }
        }
    }
    if (count($errors) == 0) {
        // mass_updates function
        include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
        if (isset($_POST['mail_address'])) {
            // update common user informations
            $fields = array($conf['user_fields']['email']);
            $data = array();
            $data[$conf['user_fields']['id']] = $userdata['id'];
            $data[$conf['user_fields']['email']] = $_POST['mail_address'];
            // password is updated only if filled
            if (!empty($_POST['use_new_pwd'])) {
                $fields[] = $conf['user_fields']['password'];
                // password is hashed with function $conf['password_hash']
                $data[$conf['user_fields']['password']] = $conf['password_hash']($_POST['use_new_pwd']);
            }
            // username is updated only if allowed
            if (!empty($_POST['username'])) {
                if ($_POST['username'] != $userdata['username'] and get_userid($_POST['username'])) {
                    $page['errors'][] = l10n('this login is already used');
                    unset($_POST['redirect']);
                } else {
                    $fields[] = $conf['user_fields']['username'];
                    $data[$conf['user_fields']['username']] = $_POST['username'];
                    // send email to the user
                    if ($_POST['username'] != $userdata['username']) {
                        include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
                        switch_lang_to($userdata['language']);
                        $keyargs_content = array(get_l10n_args('Hello', ''), get_l10n_args('Your username has been successfully changed to : %s', $_POST['username']));
                        pwg_mail($_POST['mail_address'], array('subject' => '[' . $conf['gallery_title'] . '] ' . l10n('Username modification'), 'content' => l10n_args($keyargs_content), 'content_format' => 'text/plain'));
                        switch_lang_back();
                    }
                }
            }
            mass_updates(USERS_TABLE, array('primary' => array($conf['user_fields']['id']), 'update' => $fields), array($data));
        }
        if ($conf['allow_user_customization'] or defined('IN_ADMIN')) {
            // update user "additional" informations (specific to Piwigo)
            $fields = array('nb_image_page', 'language', 'expand', 'show_nb_hits', 'recent_period', 'theme');
            if ($conf['activate_comments']) {
                $fields[] = 'show_nb_comments';
            }
            $data = array();
            $data['user_id'] = $userdata['id'];
            foreach ($fields as $field) {
                if (isset($_POST[$field])) {
                    $data[$field] = $_POST[$field];
                }
            }
            mass_updates(USER_INFOS_TABLE, array('primary' => array('user_id'), 'update' => $fields), array($data));
        }
        trigger_notify('save_profile_from_post', $userdata['id']);
        if (!empty($_POST['redirect'])) {
            redirect($_POST['redirect']);
        }
    }
    return true;
}
コード例 #9
0
ファイル: 117-database.php プロジェクト: lcorbasson/Piwigo
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH')) {
    die('Hacking attempt!');
}
$upgrade_description = 'fill empty images name with filename';
include_once PHPWG_ROOT_PATH . 'include/constants.php';
// +-----------------------------------------------------------------------+
// |                            Upgrade content                            |
// +-----------------------------------------------------------------------+
$query = 'SELECT id, file FROM ' . IMAGES_TABLE . ' WHERE name IS NULL;';
$images = pwg_query($query);
$updates = array();
while ($row = pwg_db_fetch_assoc($images)) {
    $updates[] = array('id' => $row['id'], 'name' => get_name_from_file($row['file']));
}
mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('name')), $updates);
echo "\n" . '"' . $upgrade_description . '"' . ' ended' . "\n";
コード例 #10
0
ファイル: 84-database.php プロジェクト: donseba/Piwigo
pwg_query($query);
$query = '
SELECT user_id, theme
  FROM ' . USER_INFOS_TABLE . '
;';
$result = pwg_query($query);
$users = array();
while ($row = pwg_db_fetch_assoc($result)) {
    list($user_template, $user_theme) = explode('/', $row['theme']);
    switch ($user_template) {
        case 'yoga':
            break;
        case 'gally':
            $user_theme = 'gally-' . $user_theme;
            break;
        case 'floPure':
            $user_theme = 'Pure_' . $user_theme;
            break;
        case 'floOs':
            $user_theme = 'OS_' . $user_theme;
            break;
        case 'simple':
            $user_theme = 'simple-' . $user_theme;
            break;
        default:
            $user_theme = 'Sylvia';
    }
    array_push($users, array('user_id' => $row['user_id'], 'theme' => $user_theme));
}
mass_updates(USER_INFOS_TABLE, array('primary' => array('user_id'), 'update' => array('theme')), $users);
echo "\n" . $upgrade_description . "\n";
コード例 #11
0
ファイル: tags.php プロジェクト: donseba/Piwigo
          WHERE tag_id = ' . $tag_id . '
        ;';
                    $destination_tag_image_ids = array_from_query($query, 'image_id');
                    $inserts = array();
                    foreach ($destination_tag_image_ids as $image_id) {
                        $inserts[] = array('tag_id' => $destination_tag_id, 'image_id' => $image_id);
                    }
                    if (count($inserts) > 0) {
                        mass_inserts(IMAGE_TAG_TABLE, array_keys($inserts[0]), $inserts);
                    }
                    $page['infos'][] = l10n('Tag "%s" is now a duplicate of "%s"', stripslashes($tag_name), $current_name_of[$tag_id]);
                }
            }
        }
    }
    mass_updates(TAGS_TABLE, array('primary' => array('id'), 'update' => array('name', 'url_name')), $updates);
}
// +-----------------------------------------------------------------------+
// |                               merge tags                              |
// +-----------------------------------------------------------------------+
if (isset($_POST['merge_submit'])) {
    if (!isset($_POST['destination_tag'])) {
        $page['errors'][] = l10n('No destination tag selected');
    } else {
        $destination_tag_id = $_POST['destination_tag'];
        $tag_ids = explode(',', $_POST['merge_list']);
        if (is_array($tag_ids) and count($tag_ids) > 1) {
            $name_of_tag = array();
            $query = '
SELECT
    id,
コード例 #12
0
/**
 * Update images.rating_score field.
 * We use a bayesian average (http://en.wikipedia.org/wiki/Bayesian_average) with
 *  C = average number of rates per item
 *  m = global average rate (all rates)
 *
 * @param int|false $element_id if false applies to all
 * @return array (score, average, count) values are null if $element_id is false
*/
function update_rating_score($element_id = false)
{
    if (($alt_result = trigger_change('update_rating_score', false, $element_id)) !== false) {
        return $alt_result;
    }
    $query = '
SELECT element_id,
    COUNT(rate) AS rcount,
    SUM(rate) AS rsum
  FROM ' . RATE_TABLE . '
  GROUP by element_id';
    $all_rates_count = 0;
    $all_rates_avg = 0;
    $item_ratecount_avg = 0;
    $by_item = array();
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $all_rates_count += $row['rcount'];
        $all_rates_avg += $row['rsum'];
        $by_item[$row['element_id']] = $row;
    }
    if ($all_rates_count > 0) {
        $all_rates_avg /= $all_rates_count;
        $item_ratecount_avg = $all_rates_count / count($by_item);
    }
    $updates = array();
    foreach ($by_item as $id => $rate_summary) {
        $score = ($item_ratecount_avg * $all_rates_avg + $rate_summary['rsum']) / ($item_ratecount_avg + $rate_summary['rcount']);
        $score = round($score, 2);
        if ($id == $element_id) {
            $return = array('score' => $score, 'average' => round($rate_summary['rsum'] / $rate_summary['rcount'], 2), 'count' => $rate_summary['rcount']);
        }
        $updates[] = array('id' => $id, 'rating_score' => $score);
    }
    mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('rating_score')), $updates);
    //set to null all items with no rate
    if (!isset($by_item[$element_id])) {
        $query = '
SELECT id FROM ' . IMAGES_TABLE . '
  LEFT JOIN ' . RATE_TABLE . ' ON id=element_id
  WHERE element_id IS NULL AND rating_score IS NOT NULL';
        $to_update = array_from_query($query, 'id');
        if (!empty($to_update)) {
            $query = '
UPDATE ' . IMAGES_TABLE . '
  SET rating_score=NULL
  WHERE id IN (' . implode(',', $to_update) . ')';
            pwg_query($query);
        }
    }
    return isset($return) ? $return : array('score' => null, 'average' => null, 'count' => 0);
}
コード例 #13
0
         $date_creation = null;
     } else {
         $date_creation = $_POST['date_creation'];
     }
     $datas = array();
     foreach ($collection as $image_id) {
         $datas[] = array('id' => $image_id, 'date_creation' => $date_creation);
     }
     mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('date_creation')), $datas);
 } else {
     if ('level' == $action) {
         $datas = array();
         foreach ($collection as $image_id) {
             $datas[] = array('id' => $image_id, 'level' => $_POST['level']);
         }
         mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('level')), $datas);
         if (isset($_SESSION['bulk_manager_filter']['level'])) {
             if ($_POST['level'] < $_SESSION['bulk_manager_filter']['level']) {
                 $redirect = true;
             }
         }
     } else {
         if ('add_to_caddie' == $action) {
             fill_caddie($collection);
         } else {
             if ('delete' == $action) {
                 if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) {
                     $deleted_count = delete_elements($collection, true);
                     if ($deleted_count > 0) {
                         $_SESSION['page_infos'][] = l10n_dec('%d photo was deleted', '%d photos were deleted', $deleted_count);
                         $redirect_url = get_root_url() . 'admin.php?page=' . $_GET['page'];
コード例 #14
0
ファイル: 97-database.php プロジェクト: squidjam/Piwigo
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH')) {
    die('Hacking attempt!');
}
$upgrade_description = 'makes sure default user has a theme and a language';
$query = '
SELECT
    theme,
    language
  FROM ' . USER_INFOS_TABLE . '
  WHERE user_id = ' . $conf['default_user_id'] . '
;';
$result = pwg_query($query);
list($theme, $language) = pwg_db_fetch_row($result);
$data = array('user_id' => $conf['default_user_id'], 'theme' => empty($theme) ? 'Sylvia' : $theme, 'language' => empty($language) ? 'en_UK' : $language);
mass_updates(USER_INFOS_TABLE, array('primary' => array('user_id'), 'update' => array('theme', 'language')), array($data));
echo "\n" . $upgrade_description . "\n";
コード例 #15
0
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            $infos_of_image[$row['id']] = $row;
        }
    }
    foreach ($infos_of_image as &$info) {
        $info['src_image'] = new SrcImage($info);
    }
    unset($info);
}
if (count($user_representative_updates_for)) {
    $updates = array();
    foreach ($user_representative_updates_for as $cat_id => $image_id) {
        $updates[] = array('user_id' => $user['id'], 'cat_id' => $cat_id, 'user_representative_picture_id' => $image_id);
    }
    mass_updates(USER_CACHE_CATEGORIES_TABLE, array('primary' => array('user_id', 'cat_id'), 'update' => array('user_representative_picture_id')), $updates);
}
if (count($categories) > 0) {
    // Update filtered data
    if (function_exists('update_cats_with_filtered_data')) {
        update_cats_with_filtered_data($categories);
    }
    $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl');
    trigger_notify('loc_begin_index_category_thumbnails', $categories);
    $tpl_thumbnails_var = array();
    foreach ($categories as $category) {
        if (0 == $category['count_images']) {
            continue;
        }
        $category['name'] = trigger_change('render_category_name', $category['name'], 'subcatify_category_name');
        if ($page['section'] == 'recent_cats') {
コード例 #16
0
function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, $is_subscribe = false, $check_key_list = array())
{
    global $conf, $page, $env_nbm, $conf;
    set_make_full_url();
    $check_key_treated = array();
    $updated_data_count = 0;
    $error_on_updated_data_count = 0;
    if ($is_subscribe) {
        $msg_info = l10n('User %s [%s] was added to the subscription list.');
        $msg_error = l10n('User %s [%s] was not added to the subscription list.');
    } else {
        $msg_info = l10n('User %s [%s] was removed from the subscription list.');
        $msg_error = l10n('User %s [%s] was not removed from the subscription list.');
    }
    if (count($check_key_list) != 0) {
        $updates = array();
        $enabled_value = boolean_to_string($is_subscribe);
        $data_users = get_user_notifications('subscribe', $check_key_list, !$is_subscribe);
        // Prepare message after change language
        $msg_break_timeout = l10n('Time to send mail is limited. Others mails are skipped.');
        // Begin nbm users environment
        begin_users_env_nbm(true);
        foreach ($data_users as $nbm_user) {
            if (check_sendmail_timeout()) {
                // Stop fill list on 'send', if the quota is override
                $page['errors'][] = $msg_break_timeout;
                break;
            }
            // Fill return list
            $check_key_treated[] = $nbm_user['check_key'];
            $do_update = true;
            if ($nbm_user['mail_address'] != '') {
                // set env nbm user
                set_user_on_env_nbm($nbm_user, true);
                $subject = '[' . $conf['gallery_title'] . '] ' . ($is_subscribe ? l10n('Subscribe to notification by mail') : l10n('Unsubscribe from notification by mail'));
                // Assign current var for nbm mail
                assign_vars_nbm_mail_content($nbm_user);
                $section_action_by = $is_subscribe ? 'subscribe_by_' : 'unsubscribe_by_';
                $section_action_by .= $is_admin_request ? 'admin' : 'himself';
                $env_nbm['mail_template']->assign(array($section_action_by => true, 'GOTO_GALLERY_TITLE' => $conf['gallery_title'], 'GOTO_GALLERY_URL' => get_gallery_home_url()));
                $ret = pwg_mail(array('name' => stripslashes($nbm_user['username']), 'email' => $nbm_user['mail_address']), array('from' => $env_nbm['send_as_mail_formated'], 'subject' => $subject, 'email_format' => $env_nbm['email_format'], 'content' => $env_nbm['mail_template']->parse('notification_by_mail', true), 'content_format' => $env_nbm['email_format']));
                if ($ret) {
                    inc_mail_sent_success($nbm_user);
                } else {
                    inc_mail_sent_failed($nbm_user);
                    $do_update = false;
                }
                // unset env nbm user
                unset_user_on_env_nbm();
            }
            if ($do_update) {
                $updates[] = array('check_key' => $nbm_user['check_key'], 'enabled' => $enabled_value);
                $updated_data_count += 1;
                $page['infos'][] = sprintf($msg_info, stripslashes($nbm_user['username']), $nbm_user['mail_address']);
            } else {
                $error_on_updated_data_count += 1;
                $page['errors'][] = sprintf($msg_error, stripslashes($nbm_user['username']), $nbm_user['mail_address']);
            }
        }
        // Restore nbm environment
        end_users_env_nbm();
        display_counter_info();
        mass_updates(USER_MAIL_NOTIFICATION_TABLE, array('primary' => array('check_key'), 'update' => array('enabled')), $updates);
    }
    $page['infos'][] = l10n_dec('%d user was updated.', '%d users were updated.', $updated_data_count);
    if ($error_on_updated_data_count != 0) {
        $page['errors'][] = l10n_dec('%d user was not updated.', '%d users were not updated.', $error_on_updated_data_count);
    }
    unset_make_full_url();
    return $check_key_treated;
}
コード例 #17
0
ファイル: 137-database.php プロジェクト: squidjam/Piwigo
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
$upgrade_description = 'add ASC keyword to categories image_order field';
$query = '
SELECT id, image_order
  FROM ' . CATEGORIES_TABLE . '
  WHERE image_order != ""
;';
$cats = hash_from_query($query, 'id');
foreach ($cats as $id => &$data) {
    $image_order = explode(',', $data['image_order']);
    foreach ($image_order as &$order) {
        if (strpos($order, ' ASC') === false && strpos($order, ' DESC') === false) {
            $order .= ' ASC';
        }
    }
    unset($order);
    $data['image_order'] = implode(',', $image_order);
}
unset($data);
mass_updates(CATEGORIES_TABLE, array('primary' => array('id'), 'update' => array('image_order')), $cats);
echo "\n" . $upgrade_description . "\n";
コード例 #18
0
ファイル: site_update.php プロジェクト: squidjam/Piwigo
                if (isset($data[$key])) {
                    if (!isset($tags_of[$id])) {
                        $tags_of[$id] = array();
                    }
                    foreach (explode(',', $data[$key]) as $tag_name) {
                        $tags_of[$id][] = tag_id_from_tag_name($tag_name);
                    }
                }
            }
        } else {
            $errors[] = array('path' => $element_infos['path'], 'type' => 'PWG-ERROR-NO-FS');
        }
    }
    if (!$simulate) {
        if (count($datas) > 0) {
            mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array_unique(array_merge(array_diff($site_reader->get_metadata_attributes(), array('keywords', 'tags')), array('date_metadata_update')))), $datas, isset($_POST['meta_empty_overrides']) ? 0 : MASS_UPDATES_SKIP_EMPTY);
        }
        set_tags_of($tags_of);
    }
    $template->append('footer_elements', '<!-- metadata update : ' . get_elapsed_time($start, get_moment()) . ' -->');
    $template->assign('metadata_result', array('NB_ELEMENTS_DONE' => count($datas), 'NB_ELEMENTS_CANDIDATES' => count($files), 'NB_ERRORS' => count($errors)));
}
// +-----------------------------------------------------------------------+
// |                        template initialization                        |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('update' => 'site_update.tpl'));
$result_title = '';
if (isset($simulate) and $simulate) {
    $result_title .= '[' . l10n('Simulation') . '] ';
}
// used_metadata string is displayed to inform admin which metadata will be
コード例 #19
0
function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '')
{
    global $conf, $page, $user, $lang_info, $lang, $env_nbm;
    $return_list = array();
    if (in_array($action, array('list_to_send', 'send'))) {
        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
        $is_action_send = $action == 'send';
        // disabled and null mail_address are not selected in the list
        $data_users = get_user_notifications('send', $check_key_list);
        // List all if it's define on options or on timeout
        $is_list_all_without_test = ($env_nbm['is_sendmail_timeout'] or $conf['nbm_list_all_enabled_users_to_send']);
        // Check if exist news to list user or send mails
        if (!$is_list_all_without_test or $is_action_send) {
            if (count($data_users) > 0) {
                $datas = array();
                if (!isset($customize_mail_content)) {
                    $customize_mail_content = $conf['nbm_complementary_mail_content'];
                }
                $customize_mail_content = trigger_change('nbm_render_global_customize_mail_content', $customize_mail_content);
                // Prepare message after change language
                if ($is_action_send) {
                    $msg_break_timeout = l10n('Time to send mail is limited. Others mails are skipped.');
                } else {
                    $msg_break_timeout = l10n('Prepared time for list of users to send mail is limited. Others users are not listed.');
                }
                // Begin nbm users environment
                begin_users_env_nbm($is_action_send);
                foreach ($data_users as $nbm_user) {
                    if (!$is_action_send and check_sendmail_timeout()) {
                        // Stop fill list on 'list_to_send', if the quota is override
                        $page['infos'][] = $msg_break_timeout;
                        break;
                    }
                    if ($is_action_send and check_sendmail_timeout()) {
                        // Stop fill list on 'send', if the quota is override
                        $page['errors'][] = $msg_break_timeout;
                        break;
                    }
                    // set env nbm user
                    set_user_on_env_nbm($nbm_user, $is_action_send);
                    if ($is_action_send) {
                        $auth = null;
                        $add_url_params = array();
                        $auth_key = create_user_auth_key($nbm_user['user_id'], $nbm_user['status']);
                        if ($auth_key !== false) {
                            $auth = $auth_key['auth_key'];
                            $add_url_params['auth'] = $auth;
                        }
                        set_make_full_url();
                        // Fill return list of "treated" check_key for 'send'
                        $return_list[] = $nbm_user['check_key'];
                        if ($conf['nbm_send_detailed_content']) {
                            $news = news($nbm_user['last_send'], $dbnow, false, $conf['nbm_send_html_mail'], $auth);
                            $exist_data = count($news) > 0;
                        } else {
                            $exist_data = news_exists($nbm_user['last_send'], $dbnow);
                        }
                        if ($exist_data) {
                            $subject = '[' . $conf['gallery_title'] . '] ' . l10n('New photos added');
                            // Assign current var for nbm mail
                            assign_vars_nbm_mail_content($nbm_user);
                            if (!is_null($nbm_user['last_send'])) {
                                $env_nbm['mail_template']->assign('content_new_elements_between', array('DATE_BETWEEN_1' => $nbm_user['last_send'], 'DATE_BETWEEN_2' => $dbnow));
                            } else {
                                $env_nbm['mail_template']->assign('content_new_elements_single', array('DATE_SINGLE' => $dbnow));
                            }
                            if ($conf['nbm_send_detailed_content']) {
                                $env_nbm['mail_template']->assign('global_new_lines', $news);
                            }
                            $nbm_user_customize_mail_content = trigger_change('nbm_render_user_customize_mail_content', $customize_mail_content, $nbm_user);
                            if (!empty($nbm_user_customize_mail_content)) {
                                $env_nbm['mail_template']->assign('custom_mail_content', $nbm_user_customize_mail_content);
                            }
                            if ($conf['nbm_send_html_mail'] and $conf['nbm_send_recent_post_dates']) {
                                $recent_post_dates = get_recent_post_dates_array($conf['recent_post_dates']['NBM']);
                                foreach ($recent_post_dates as $date_detail) {
                                    $env_nbm['mail_template']->append('recent_posts', array('TITLE' => get_title_recent_post_date($date_detail), 'HTML_DATA' => get_html_description_recent_post_date($date_detail, $auth)));
                                }
                            }
                            $env_nbm['mail_template']->assign(array('GOTO_GALLERY_TITLE' => $conf['gallery_title'], 'GOTO_GALLERY_URL' => add_url_params(get_gallery_home_url(), $add_url_params), 'SEND_AS_NAME' => $env_nbm['send_as_name']));
                            $ret = pwg_mail(array('name' => stripslashes($nbm_user['username']), 'email' => $nbm_user['mail_address']), array('from' => $env_nbm['send_as_mail_formated'], 'subject' => $subject, 'email_format' => $env_nbm['email_format'], 'content' => $env_nbm['mail_template']->parse('notification_by_mail', true), 'content_format' => $env_nbm['email_format'], 'auth_key' => $auth));
                            if ($ret) {
                                inc_mail_sent_success($nbm_user);
                                $datas[] = array('user_id' => $nbm_user['user_id'], 'last_send' => $dbnow);
                            } else {
                                inc_mail_sent_failed($nbm_user);
                            }
                            unset_make_full_url();
                        }
                    } else {
                        if (news_exists($nbm_user['last_send'], $dbnow)) {
                            // Fill return list of "selected" users for 'list_to_send'
                            $return_list[] = $nbm_user;
                        }
                    }
                    // unset env nbm user
                    unset_user_on_env_nbm();
                }
                // Restore nbm environment
                end_users_env_nbm();
                if ($is_action_send) {
                    mass_updates(USER_MAIL_NOTIFICATION_TABLE, array('primary' => array('user_id'), 'update' => array('last_send')), $datas);
                    display_counter_info();
                }
            } else {
                if ($is_action_send) {
                    $page['errors'][] = l10n('No user to send notifications by mail.');
                }
            }
        } else {
            // Quick List, don't check news
            // Fill return list of "selected" users for 'list_to_send'
            $return_list = $data_users;
        }
    }
    // Return list of "selected" users for 'list_to_send'
    // Return list of "treated" check_key for 'send'
    return $return_list;
}
コード例 #20
0
function osm_loc_begin_element_set_unit()
{
    global $page;
    if (!isset($_POST['submit'])) {
        return;
    }
    $collection = explode(',', $_POST['element_ids']);
    $query = "SELECT `id`, `latitude`, `longitude`\n\t\t\tFROM " . IMAGES_TABLE . "\n\t\t\tWHERE id IN (" . implode(',', $collection) . ")";
    $datas = array();
    $errors = array();
    $form_errors = 0;
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        if (!isset($_POST['osmlat-' . $row['id']])) {
            $form_errors++;
            continue;
        }
        $error = false;
        $data = array('id' => $row['id'], 'latitude' => trim($_POST['osmlat-' . $row['id']]), 'longitude' => trim($_POST['osmlon-' . $row['id']]));
        if (strlen($data['latitude']) > 0 and strlen($data['longitude']) > 0) {
            if (!is_numeric($data['latitude']) or !is_numeric($data['longitude']) or (double) $data['latitude'] > 90 or (double) $data['latitude'] < -90 or (double) $data['longitude'] > 180 or (double) $data['longitude'] < -180) {
                $error = true;
            }
        } elseif (strlen($data['latitude']) == 0 and strlen($data['longitude']) == 0) {
            // nothing
        } else {
            $error = true;
        }
        if ($error) {
            $errors[] = $row['name'];
        } else {
            $datas[] = $data;
        }
    }
    mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('latitude', 'longitude')), $datas);
    if (count($errors) > 0) {
        $page['errors'][] = 'Invalid latitude or longitude value for files: ' . implode(', ', $errors);
    }
    if ($form_errors) {
        $page['errors'][] = 'OpenStreetMap: Invalid form submission for ' . $form_errors . ' photos';
    }
}
コード例 #21
0
ファイル: 122-database.php プロジェクト: squidjam/Piwigo
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH')) {
    die('Hacking attempt!');
}
$upgrade_description = 'derivatives: new organization of "upload" and "galleries" directories';
$query = '
SELECT
    id,
    path,
    tn_ext,
    has_high,
    high_filesize,
    high_width,
    high_height
  FROM ' . IMAGES_TABLE . '
;';
$result = pwg_query($query);
$starttime = get_moment();
$updates = array();
while ($row = pwg_db_fetch_assoc($result)) {
    if ('true' == $row['has_high']) {
        $high_path = dirname($row['path']) . '/pwg_high/' . basename($row['path']);
        rename($high_path, $row['path']);
        array_push($updates, array('id' => $row['id'], 'width' => $row['high_width'], 'height' => $row['high_height'], 'filesize' => $row['high_filesize']));
    }
}
if (count($updates) > 0) {
    mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('width', 'height', 'filesize')), $updates);
}
echo "\n" . $upgrade_description . sprintf(' (execution in %.3fs)', get_moment() - $starttime) . "\n";
コード例 #22
0
ファイル: upgrade_1.3.0.php プロジェクト: squidjam/Piwigo
    pwg_query($query);
}
// filling the new column categories.uppercats
$id_uppercats = array();
$query = '
SELECT id, id_uppercat
  FROM ' . CATEGORIES_TABLE . '
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result)) {
    if (!isset($row['id_uppercat']) or $row['id_uppercat'] == '') {
        $row['id_uppercat'] = 'NULL';
    }
    $id_uppercats[$row['id']] = $row['id_uppercat'];
}
$datas = array();
foreach (array_keys($id_uppercats) as $id) {
    $data = array();
    $data['id'] = $id;
    $uppercats = array();
    array_push($uppercats, $id);
    while (isset($id_uppercats[$id]) and $id_uppercats[$id] != 'NULL') {
        array_push($uppercats, $id_uppercats[$id]);
        $id = $id_uppercats[$id];
    }
    $data['uppercats'] = implode(',', array_reverse($uppercats));
    array_push($datas, $data);
}
mass_updates(CATEGORIES_TABLE, array('primary' => array('id'), 'update' => array('uppercats')), $datas);
// now we upgrade from 1.3.1 to 1.6.0
include_once PHPWG_ROOT_PATH . 'install/upgrade_1.3.1.php';
コード例 #23
0
ファイル: batch_manager_unit.php プロジェクト: donseba/Piwigo
            $data['comment'] = strip_tags(@$_POST['description-' . $row['id']]);
        }
        if (!empty($_POST['date_creation-' . $row['id']])) {
            $data['date_creation'] = $_POST['date_creation-' . $row['id']];
        } else {
            $data['date_creation'] = null;
        }
        $datas[] = $data;
        // tags management
        $tag_ids = array();
        if (!empty($_POST['tags-' . $row['id']])) {
            $tag_ids = get_tag_ids($_POST['tags-' . $row['id']]);
        }
        set_tags($tag_ids, $row['id']);
    }
    mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('name', 'author', 'level', 'comment', 'date_creation')), $datas);
    $page['infos'][] = l10n('Photo informations updated');
    invalidate_user_cache();
}
// +-----------------------------------------------------------------------+
// |                             template init                             |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('batch_manager_unit' => 'batch_manager_unit.tpl'));
$base_url = PHPWG_ROOT_PATH . 'admin.php';
$template->assign(array('U_ELEMENTS_PAGE' => $base_url . get_query_string_diff(array('display', 'start')), 'F_ACTION' => $base_url . get_query_string_diff(array()), 'level_options' => get_privacy_level_options()));
// +-----------------------------------------------------------------------+
// |                        global mode thumbnails                         |
// +-----------------------------------------------------------------------+
// how many items to display on this page
if (!empty($_GET['display'])) {
    $page['nb_images'] = intval($_GET['display']);
コード例 #24
0
 /**
  * Do correction user
  *
  * @param user_id, action
  * @return boolean true if ok else false
  */
 function c13y_correction_user($id, $action)
 {
     global $conf, $page;
     $result = false;
     if (!empty($id)) {
         switch ($action) {
             case 'creation':
                 if ($id == $conf['guest_id']) {
                     $name = 'guest';
                     $password = null;
                 } else {
                     if ($id == $conf['default_user_id']) {
                         $name = 'guest';
                         $password = null;
                     } else {
                         if ($id == $conf['webmaster_id']) {
                             $name = 'webmaster';
                             $password = generate_key(6);
                         }
                     }
                 }
                 if (isset($name)) {
                     $name_ok = false;
                     while (!$name_ok) {
                         $name_ok = get_userid($name) === false;
                         if (!$name_ok) {
                             $name .= generate_key(1);
                         }
                     }
                     $inserts = array(array('id' => $id, 'username' => addslashes($name), 'password' => $password));
                     mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts);
                     create_user_infos($id);
                     $page['infos'][] = sprintf(l10n('User "%s" created with "%s" like password'), $name, $password);
                     $result = true;
                 }
                 break;
             case 'status':
                 if ($id == $conf['guest_id']) {
                     $status = 'guest';
                 } else {
                     if ($id == $conf['default_user_id']) {
                         $status = 'guest';
                     } else {
                         if ($id == $conf['webmaster_id']) {
                             $status = 'webmaster';
                         }
                     }
                 }
                 if (isset($status)) {
                     $updates = array(array('user_id' => $id, 'status' => $status));
                     mass_updates(USER_INFOS_TABLE, array('primary' => array('user_id'), 'update' => array('status')), $updates);
                     $page['infos'][] = sprintf(l10n('Status of user "%s" updated'), get_username($id));
                     $result = true;
                 }
                 break;
         }
     }
     return $result;
 }
コード例 #25
0
    }
    $updates = array();
    // we must not rename tag with an already existing name
    foreach (explode(',', $_POST['edit_list']) as $place_id) {
        $place_name = stripslashes($_POST['place_name-' . $place_id]);
        $place_lat = stripslashes($_POST['place_lat-' . $place_id]);
        $place_lon = stripslashes($_POST['place_lon-' . $place_id]);
        if (in_array($place_name, $existing_names)) {
            $page['errors'][] = l10n('Place "%s" already exists', $place_name);
        } else {
            if (!empty($place_name)) {
                $updates[] = array('id' => $place_id, 'name' => addslashes($place_name), 'latitude' => $place_lat, 'longitude' => $place_lon);
            }
        }
    }
    mass_updates(osm_place_table, array('primary' => array('id'), 'update' => array('name', 'latitude', 'longitude')), $updates);
}
// +-----------------------------------------------------------------------+
// |                               delete places                           |
// +-----------------------------------------------------------------------+
if (isset($_POST['delete']) and isset($_POST['places'])) {
    $query = '
SELECT name
  FROM ' . osm_place_table . '
  WHERE id IN (' . implode(',', $_POST['places']) . ')
;';
    $place_names = array_from_query($query, 'name');
    $query = '
DELETE
  FROM ' . osm_place_table . '
  WHERE id IN (' . implode(',', $_POST['places']) . ')