Ejemplo n.º 1
0
function NBMS_Save_Profile()
{
    global $conf, $user;
    include_once PHPWG_ROOT_PATH . 'admin/include/functions_notification_by_mail.inc.php';
    $query = '
SELECT *
FROM ' . USER_MAIL_NOTIFICATION_TABLE . '
WHERE user_id = \'' . $user['id'] . '\'
';
    $count = pwg_db_num_rows(pwg_query($query));
    if ($count == 0) {
        $inserts = array();
        $check_key_list = array();
        // Calculate key
        $nbm_user['check_key'] = find_available_check_key();
        // Save key
        array_push($check_key_list, $nbm_user['check_key']);
        // Insert new nbm_users
        array_push($inserts, array('user_id' => $user['id'], 'check_key' => $nbm_user['check_key'], 'enabled' => $_POST['NBM_Subscription']));
        mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
    } elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false'))) {
        $query = '
UPDATE ' . USER_MAIL_NOTIFICATION_TABLE . '
  SET enabled = \'' . $_POST['NBM_Subscription'] . '\'
  WHERE user_id = \'' . $user['id'] . '\';';
        pwg_query($query);
    }
}
Ejemplo n.º 2
0
function update_user($username, $id)
{
    $up = new Ldap();
    $up->load_config();
    $up->ldap_conn() or error_log("Unable to connect LDAP server : " . $up->getErrorString());
    // update user piwigo rights / access according to ldap. Only if it's webmaster / admin, so no normal !
    if ($up->ldap_status($username) != 'normal') {
        single_update(USER_INFOS_TABLE, array('status' => $up->ldap_status($username)), array('user_id' => $id));
    }
    // search groups
    $group_query = 'SELECT name, id FROM ' . GROUPS_TABLE . ';';
    $result = pwg_query($group_query);
    $inserts = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        if ($up->user_membership($username, $up->ldap_group($row['name']))) {
            $inserts[] = array('user_id' => $id, 'group_id' => $row['id']);
        }
    }
    if (count($inserts) > 0) {
        mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $inserts, array('ignore' => true));
    }
}
Ejemplo n.º 3
0
     }
     $insert = array('id' => $next_element_id++, 'file' => $filename, 'name' => get_name_from_file($filename), 'date_available' => CURRENT_DATE, 'path' => $path, 'representative_ext' => $fs[$path]['representative_ext'], 'storage_category_id' => $db_fulldirs[$dirname], 'added_by' => $user['id']);
     if ($_POST['privacy_level'] != 0) {
         $insert['level'] = $_POST['privacy_level'];
     }
     $inserts[] = $insert;
     $insert_links[] = array('image_id' => $insert['id'], 'category_id' => $insert['storage_category_id']);
     $infos[] = array('path' => $insert['path'], 'info' => l10n('added'));
     $caddiables[] = $insert['id'];
 }
 if (count($inserts) > 0) {
     if (!$simulate) {
         // inserts all new elements
         mass_inserts(IMAGES_TABLE, array_keys($inserts[0]), $inserts);
         // inserts all links between new elements and their storage category
         mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($insert_links[0]), $insert_links);
         // add new photos to caddie
         if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1) {
             fill_caddie($caddiables);
         }
     }
     $counts['new_elements'] = count($inserts);
 }
 // delete elements that are in database but not in the filesystem
 $to_delete_elements = array();
 foreach (array_diff($db_elements, array_keys($fs)) as $path) {
     $to_delete_elements[] = array_search($path, $db_elements);
     $infos[] = array('path' => $path, 'info' => l10n('deleted'));
 }
 if (count($to_delete_elements) > 0) {
     if (!$simulate) {
Ejemplo n.º 4
0
        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                                                 |
// +-----------------------------------------------------------------------+
foreach (array('day', 'month', 'year') as $key) {
    if (isset($_GET[$key])) {
Ejemplo n.º 5
0
/**
 * Creates user informations based on default values.
 *
 * @param int|int[] $user_ids
 * @param array $override_values values used to override default user values
 */
function create_user_infos($user_ids, $override_values = null)
{
    global $conf;
    if (!is_array($user_ids)) {
        $user_ids = array($user_ids);
    }
    if (!empty($user_ids)) {
        $inserts = array();
        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
        $default_user = get_default_user_info(false);
        if ($default_user === false) {
            // Default on structure are used
            $default_user = array();
        }
        if (!is_null($override_values)) {
            $default_user = array_merge($default_user, $override_values);
        }
        foreach ($user_ids as $user_id) {
            $level = isset($default_user['level']) ? $default_user['level'] : 0;
            if ($user_id == $conf['webmaster_id']) {
                $status = 'webmaster';
                $level = max($conf['available_permission_levels']);
            } elseif ($user_id == $conf['guest_id'] or $user_id == $conf['default_user_id']) {
                $status = 'guest';
            } else {
                $status = 'normal';
            }
            $insert = array_merge($default_user, array('user_id' => $user_id, 'status' => $status, 'registration_date' => $dbnow, 'level' => $level));
            $inserts[] = $insert;
        }
        mass_inserts(USER_INFOS_TABLE, array_keys($inserts[0]), $inserts);
    }
}
Ejemplo n.º 6
0
         $res = pwg_query($query);
         while ($row = pwg_db_fetch_assoc($res)) {
             $grp_access[] = array('cat_id' => $row['cat_id'], 'group_id' => $groupid);
         }
         mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $grp_access);
         $query = '
 SELECT *
   FROM ' . USER_GROUP_TABLE . '
   WHERE group_id = ' . $group . '
 ;';
         $usr_grp = array();
         $res = pwg_query($query);
         while ($row = pwg_db_fetch_assoc($res)) {
             $usr_grp[] = array('user_id' => $row['user_id'], 'group_id' => $groupid);
         }
         mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $usr_grp);
         $page['infos'][] = l10n('group "%s" added', $_POST['duplicate_' . $group . '']);
     }
 }
 // +
 // | toggle_default
 // +
 if ($action == "toggle_default") {
     foreach ($groups as $group) {
         $query = '
 SELECT name, is_default
   FROM ' . GROUPS_TABLE . '
   WHERE id = ' . $group . '
 ;';
         list($groupname, $is_default) = pwg_db_fetch_row(pwg_query($query));
         // update of the group
Ejemplo n.º 7
0
/**
 * API method
 * Adds images to the caddie
 * @param mixed[] $params
 *    @option int[] image_id
 */
function ws_caddie_add($params, &$service)
{
    global $user;
    $query = '
SELECT id
  FROM ' . IMAGES_TABLE . '
      LEFT JOIN ' . CADDIE_TABLE . '
      ON id=element_id AND user_id=' . $user['id'] . '
  WHERE id IN (' . implode(',', $params['image_id']) . ')
    AND element_id IS NULL
;';
    $result = array_from_query($query, 'id');
    $datas = array();
    foreach ($result as $id) {
        $datas[] = array('element_id' => $id, 'user_id' => $user['id']);
    }
    if (count($datas)) {
        mass_inserts(CADDIE_TABLE, array('element_id', 'user_id'), $datas);
    }
    return count($datas);
}
Ejemplo n.º 8
0
/**
 * fill the current user caddie with given elements, if not already in caddie
 *
 * @param int[] $elements_id
 */
function fill_caddie($elements_id)
{
    global $user;
    $query = '
SELECT element_id
  FROM ' . CADDIE_TABLE . '
  WHERE user_id = ' . $user['id'] . '
;';
    $in_caddie = query2array($query, null, 'element_id');
    $caddiables = array_diff($elements_id, $in_caddie);
    $datas = array();
    foreach ($caddiables as $caddiable) {
        $datas[] = array('element_id' => $caddiable, 'user_id' => $user['id']);
    }
    if (count($caddiables) > 0) {
        mass_inserts(CADDIE_TABLE, array('element_id', 'user_id'), $datas);
    }
}
Ejemplo n.º 9
0
/**
 * API method
 * Add permissions
 * @param mixed[] $params
 *    @option int[] cat_id
 *    @option int[] group_id (optional)
 *    @option int[] user_id (optional)
 *    @option bool recursive
 */
function ws_permissions_add($params, &$service)
{
    if (get_pwg_token() != $params['pwg_token']) {
        return new PwgError(403, 'Invalid security token');
    }
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    if (!empty($params['group_id'])) {
        $cat_ids = get_uppercat_ids($params['cat_id']);
        if ($params['recursive']) {
            $cat_ids = array_merge($cat_ids, get_subcat_ids($params['cat_id']));
        }
        $query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (' . implode(',', $cat_ids) . ')
    AND status = \'private\'
;';
        $private_cats = array_from_query($query, 'id');
        $inserts = array();
        foreach ($private_cats as $cat_id) {
            foreach ($params['group_id'] as $group_id) {
                $inserts[] = array('group_id' => $group_id, 'cat_id' => $cat_id);
            }
        }
        mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $inserts, array('ignore' => true));
    }
    if (!empty($params['user_id'])) {
        if ($params['recursive']) {
            $_POST['apply_on_sub'] = true;
        }
        add_permission_on_category($params['cat_id'], $params['user_id']);
    }
    return $service->invoke('pwg.permissions.getList', array('cat_id' => $params['cat_id']));
}
Ejemplo n.º 10
0
function insert_new_data_user_mail_notification()
{
    global $conf, $page, $env_nbm;
    // Set null mail_address empty
    $query = '
update
  ' . USERS_TABLE . '
set
  ' . $conf['user_fields']['email'] . ' = null
where
  trim(' . $conf['user_fields']['email'] . ') = \'\';';
    pwg_query($query);
    // null mail_address are not selected in the list
    $query = '
select
  u.' . $conf['user_fields']['id'] . ' as user_id,
  u.' . $conf['user_fields']['username'] . ' as username,
  u.' . $conf['user_fields']['email'] . ' as mail_address
from
  ' . USERS_TABLE . ' as u left join ' . USER_MAIL_NOTIFICATION_TABLE . ' as m on u.' . $conf['user_fields']['id'] . ' = m.user_id
where
  u.' . $conf['user_fields']['email'] . ' is not null and
  m.user_id is null
order by
  user_id;';
    $result = pwg_query($query);
    if (pwg_db_num_rows($result) > 0) {
        $inserts = array();
        $check_key_list = array();
        while ($nbm_user = pwg_db_fetch_assoc($result)) {
            // Calculate key
            $nbm_user['check_key'] = find_available_check_key();
            // Save key
            $check_key_list[] = $nbm_user['check_key'];
            // Insert new nbm_users
            $inserts[] = array('user_id' => $nbm_user['user_id'], 'check_key' => $nbm_user['check_key'], 'enabled' => 'false');
            $page['infos'][] = l10n('User %s [%s] added.', stripslashes($nbm_user['username']), $nbm_user['mail_address']);
        }
        // Insert new nbm_users
        mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
        // Update field enabled with specific function
        $check_key_treated = do_subscribe_unsubscribe_notification_by_mail(true, $conf['nbm_default_value_user_enabled'], $check_key_list);
        // On timeout simulate like tabsheet send
        if ($env_nbm['is_sendmail_timeout']) {
            $quoted_check_key_list = quote_check_key_list(array_diff($check_key_list, $check_key_treated));
            if (count($quoted_check_key_list) != 0) {
                $query = 'delete from ' . USER_MAIL_NOTIFICATION_TABLE . ' where check_key in (' . implode(",", $quoted_check_key_list) . ');';
                $result = pwg_query($query);
                redirect($base_url . get_query_string_diff(array(), false), l10n('Operation in progress') . "\n" . l10n('Please wait...'));
            }
        }
    }
}
Ejemplo n.º 11
0
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined('PHOTOS_ADD_BASE_URL')) {
    die("Hacking attempt!");
}
// +-----------------------------------------------------------------------+
// |                        batch management request                       |
// +-----------------------------------------------------------------------+
if (isset($_GET['batch'])) {
    check_input_parameter('batch', $_GET, false, '/^\\d+(,\\d+)*$/');
    $query = '
DELETE FROM ' . CADDIE_TABLE . '
  WHERE user_id = ' . $user['id'] . '
;';
    pwg_query($query);
    $inserts = array();
    foreach (explode(',', $_GET['batch']) as $image_id) {
        $inserts[] = array('user_id' => $user['id'], 'element_id' => $image_id);
    }
    mass_inserts(CADDIE_TABLE, array_keys($inserts[0]), $inserts);
    redirect(get_root_url() . 'admin.php?page=batch_manager&filter=prefilter-caddie');
}
// +-----------------------------------------------------------------------+
// |                             prepare form                              |
// +-----------------------------------------------------------------------+
include_once PHPWG_ROOT_PATH . 'admin/include/photos_add_direct_prepare.inc.php';
// +-----------------------------------------------------------------------+
// |                           sending html code                           |
// +-----------------------------------------------------------------------+
trigger_notify('loc_end_photo_add_direct');
$template->assign_var_from_handle('ADMIN_CONTENT', 'photos_add');
Ejemplo n.º 12
0
/**
 * API method
 * Adds user(s) to a group
 * @param mixed[] $params
 *    @option int group_id
 *    @option int[] user_id
 */
function ws_groups_addUser($params, &$service)
{
    if (get_pwg_token() != $params['pwg_token']) {
        return new PwgError(403, 'Invalid security token');
    }
    // does the group exist ?
    $query = '
SELECT COUNT(*)
  FROM ' . GROUPS_TABLE . '
  WHERE id = ' . $params['group_id'] . '
;';
    list($count) = pwg_db_fetch_row(pwg_query($query));
    if ($count == 0) {
        return new PwgError(WS_ERR_INVALID_PARAM, 'This group does not exist.');
    }
    $inserts = array();
    foreach ($params['user_id'] as $user_id) {
        $inserts[] = array('group_id' => $params['group_id'], 'user_id' => $user_id);
    }
    mass_inserts(USER_GROUP_TABLE, array('group_id', 'user_id'), $inserts, array('ignore' => true));
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    invalidate_user_cache();
    return $service->invoke('pwg.groups.getList', array('group_id' => $params['group_id']));
}
Ejemplo n.º 13
0
    }
    foreach ($indexes_of[$table] as $index_name => $index) {
        if (!in_array($index_name, $existing_indexes)) {
            $query = '
ALTER TABLE ' . PREFIX_TABLE . $table . '
  ADD ' . ($index['unique'] ? 'UNIQUE' : 'INDEX') . ' ' . $index_name . ' (' . implode(',', $index['columns']) . ')
;';
            pwg_query($query);
        }
    }
}
//
// insert params in new configuration table
//
$params = array(array('param' => 'prefix_thumbnail', 'value' => $save['prefix_thumbnail'], 'comment' => 'thumbnails filename prefix'), array('param' => 'mail_webmaster', 'value' => $save['mail_webmaster'], 'comment' => 'webmaster mail'), array('param' => 'default_language', 'value' => 'en_UK.iso-8859-1', 'comment' => 'Default gallery language'), array('param' => 'default_template', 'value' => 'default', 'comment' => 'Default gallery style'), array('param' => 'default_maxwidth', 'value' => '', 'comment' => 'maximum width authorized for displaying images'), array('param' => 'default_maxheight', 'value' => '', 'comment' => 'maximum height authorized for the displaying images'), array('param' => 'nb_comment_page', 'value' => '10', 'comment' => 'number of comments to display on each page'), array('param' => 'upload_maxfilesize', 'value' => '150', 'comment' => 'maximum filesize for the uploaded pictures'), array('param' => 'upload_maxwidth', 'value' => '800', 'comment' => 'maximum width authorized for the uploaded images'), array('param' => 'upload_maxheight', 'value' => '600', 'comment' => 'maximum height authorized for the uploaded images'), array('param' => 'upload_maxwidth_thumbnail', 'value' => '150', 'comment' => 'maximum width authorized for the uploaded thumbnails'), array('param' => 'upload_maxheight_thumbnail', 'value' => '100', 'comment' => 'maximum height authorized for the uploaded thumbnails'), array('param' => 'log', 'value' => 'false', 'comment' => 'keep an history of visits on your website'), array('param' => 'comments_validation', 'value' => 'false', 'comment' => 'administrators validate users comments before becoming visible'), array('param' => 'comments_forall', 'value' => 'false', 'comment' => 'even guest not registered can post comments'), array('param' => 'mail_notification', 'value' => 'false', 'comment' => 'automated mail notification for adminsitrators'), array('param' => 'nb_image_line', 'value' => '5', 'comment' => 'Number of images displayed per row'), array('param' => 'nb_line_page', 'value' => '3', 'comment' => 'Number of rows displayed per page'), array('param' => 'recent_period', 'value' => '7', 'comment' => 'Period within which pictures are displayed as new (in days)'), array('param' => 'auto_expand', 'value' => 'false', 'comment' => 'Auto expand of the category tree'), array('param' => 'show_nb_comments', 'value' => 'false', 'comment' => 'Show the number of comments under the thumbnails'), array('param' => 'use_iptc', 'value' => 'false', 'comment' => 'Use IPTC data during database synchronization with files metadata'), array('param' => 'use_exif', 'value' => 'false', 'comment' => 'Use EXIF data during database synchronization with files metadata'), array('param' => 'show_iptc', 'value' => 'false', 'comment' => 'Show IPTC metadata on picture.php if asked by user'), array('param' => 'show_exif', 'value' => 'true', 'comment' => 'Show EXIF metadata on picture.php if asked by user'), array('param' => 'authorize_remembering', 'value' => 'true', 'comment' => 'Authorize users to be remembered, see $conf{remember_me_length}'), array('param' => 'gallery_locked', 'value' => 'false', 'comment' => 'Lock your gallery temporary for non admin users'));
mass_inserts(CONFIG_TABLE, array_keys($params[0]), $params);
// refresh calculated datas
update_global_rank();
update_category();
// update calculated field "images.path"
$cat_ids = array();
$query = '
SELECT DISTINCT(storage_category_id) AS unique_storage_category_id
  FROM ' . IMAGES_TABLE . '
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result)) {
    array_push($cat_ids, $row['unique_storage_category_id']);
}
$fulldirs = get_fulldirs($cat_ids);
foreach ($cat_ids as $cat_id) {
Ejemplo n.º 14
0
<?php 
$show_form = true;
if (isset($_POST['image_id'])) {
    if (!preg_match('#^[0-9]+$#', $_POST['image_id'])) {
        echo '<h3>Incorrect image Id</h3><br>';
    } else {
        $query = '
SELECT * FROM ' . COMMENTS_TABLE . '
  WHERE image_id = ' . $_POST['image_id'] . '
;';
        $comms = hash_from_query($query, 'id');
        if (!count($comms)) {
            echo '<h3>No comments for this picture</h3><br>';
        } else {
            mass_inserts(GUESTBOOK_TABLE, array('date', 'author', 'author_id', 'anonymous_id', 'email', 'website', 'content', 'rate', 'validated', 'validation_date'), $comms);
            echo '<h3>' . count($comms) . ' comments imported into the Guestbook</h3><br>';
            $show_form = false;
        }
    }
}
if ($show_form) {
    ?>
Just enter the ID of your old guestbook picture (the ID can be found a the picture edition page, near the thumbnail) and click the <b>import</b> button.
<form action="" method="post">
<label>Image ID : <input type="text" size="5" name="image_id"></label><br>
<input type="submit" value="import">
</form>

<?php 
}
Ejemplo n.º 15
0
            $image_ids = array_from_query($query, 'image_id');
            delete_tags($tag_ids_to_delete);
            $query = '
SELECT
    image_id
  FROM ' . IMAGE_TAG_TABLE . '
  WHERE tag_id = ' . $destination_tag_id . '
;';
            $destination_tag_image_ids = array_from_query($query, 'image_id');
            $image_ids_to_link = array_diff($image_ids, $destination_tag_image_ids);
            $inserts = array();
            foreach ($image_ids_to_link 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);
            }
            $tags_deleted = array();
            foreach ($tag_ids_to_delete as $tag_id) {
                $tags_deleted[] = $name_of_tag[$tag_id];
            }
            $page['infos'][] = l10n('Tags <em>%s</em> merged into tag <em>%s</em>', implode(', ', $tags_deleted), $name_of_tag[$destination_tag_id]);
        }
    }
}
// +-----------------------------------------------------------------------+
// |                               delete tags                             |
// +-----------------------------------------------------------------------+
if (isset($_POST['delete']) and isset($_POST['tags'])) {
    $query = '
SELECT name
Ejemplo n.º 16
0
/**
 * Sets associations of an image
 * @param int $image_id
 * @param string $categories_string - "cat_id[,rank];cat_id[,rank]"
 * @param bool $replace_mode - removes old associations
 */
function ws_add_image_category_relations($image_id, $categories_string, $replace_mode = false)
{
    // let's add links between the image and the categories
    //
    // $params['categories'] should look like 123,12;456,auto;789 which means:
    //
    // 1. associate with category 123 on rank 12
    // 2. associate with category 456 on automatic rank
    // 3. associate with category 789 on automatic rank
    $cat_ids = array();
    $rank_on_category = array();
    $search_current_ranks = false;
    $tokens = explode(';', $categories_string);
    foreach ($tokens as $token) {
        @(list($cat_id, $rank) = explode(',', $token));
        if (!preg_match('/^\\d+$/', $cat_id)) {
            continue;
        }
        $cat_ids[] = $cat_id;
        if (!isset($rank)) {
            $rank = 'auto';
        }
        $rank_on_category[$cat_id] = $rank;
        if ($rank == 'auto') {
            $search_current_ranks = true;
        }
    }
    $cat_ids = array_unique($cat_ids);
    if (count($cat_ids) == 0) {
        return new PwgError(500, '[ws_add_image_category_relations] there is no category defined in "' . $categories_string . '"');
    }
    $query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (' . implode(',', $cat_ids) . ')
;';
    $db_cat_ids = query2array($query, null, 'id');
    $unknown_cat_ids = array_diff($cat_ids, $db_cat_ids);
    if (count($unknown_cat_ids) != 0) {
        return new PwgError(500, '[ws_add_image_category_relations] the following categories are unknown: ' . implode(', ', $unknown_cat_ids));
    }
    $to_update_cat_ids = array();
    // in case of replace mode, we first check the existing associations
    $query = '
SELECT category_id
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE image_id = ' . $image_id . '
;';
    $existing_cat_ids = query2array($query, null, 'category_id');
    if ($replace_mode) {
        $to_remove_cat_ids = array_diff($existing_cat_ids, $cat_ids);
        if (count($to_remove_cat_ids) > 0) {
            $query = '
DELETE
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE image_id = ' . $image_id . '
    AND category_id IN (' . implode(', ', $to_remove_cat_ids) . ')
;';
            pwg_query($query);
            update_category($to_remove_cat_ids);
        }
    }
    $new_cat_ids = array_diff($cat_ids, $existing_cat_ids);
    if (count($new_cat_ids) == 0) {
        return true;
    }
    if ($search_current_ranks) {
        $query = '
SELECT category_id, MAX(rank) AS max_rank
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE rank IS NOT NULL
    AND category_id IN (' . implode(',', $new_cat_ids) . ')
  GROUP BY category_id
;';
        $current_rank_of = query2array($query, 'category_id', 'max_rank');
        foreach ($new_cat_ids as $cat_id) {
            if (!isset($current_rank_of[$cat_id])) {
                $current_rank_of[$cat_id] = 0;
            }
            if ('auto' == $rank_on_category[$cat_id]) {
                $rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1;
            }
        }
    }
    $inserts = array();
    foreach ($new_cat_ids as $cat_id) {
        $inserts[] = array('image_id' => $image_id, 'category_id' => $cat_id, 'rank' => $rank_on_category[$cat_id]);
    }
    mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($inserts[0]), $inserts);
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    update_category($new_cat_ids);
}
Ejemplo n.º 17
0
/**
 * replace old style #images.keywords by #tags. Requires a big data
 * migration.
 *
 * @return void
 */
function tag_replace_keywords()
{
    // code taken from upgrades 19 and 22
    $query = '
CREATE TABLE ' . PREFIX_TABLE . 'tags (
  id smallint(5) UNSIGNED NOT NULL auto_increment,
  name varchar(255) BINARY NOT NULL,
  url_name varchar(255) BINARY NOT NULL,
  PRIMARY KEY (id)
)
;';
    pwg_query($query);
    $query = '
CREATE TABLE ' . PREFIX_TABLE . 'image_tag (
  image_id mediumint(8) UNSIGNED NOT NULL,
  tag_id smallint(5) UNSIGNED NOT NULL,
  PRIMARY KEY (image_id,tag_id)
)
;';
    pwg_query($query);
    //
    // Move keywords to tags
    //
    // each tag label is associated to a numeric identifier
    $tag_id = array();
    // to each tag id (key) a list of image ids (value) is associated
    $tag_images = array();
    $current_id = 1;
    $query = '
SELECT id, keywords
  FROM ' . PREFIX_TABLE . 'images
  WHERE keywords IS NOT NULL
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        foreach (preg_split('/[,]+/', $row['keywords']) as $keyword) {
            if (!isset($tag_id[$keyword])) {
                $tag_id[$keyword] = $current_id++;
            }
            if (!isset($tag_images[$tag_id[$keyword]])) {
                $tag_images[$tag_id[$keyword]] = array();
            }
            array_push($tag_images[$tag_id[$keyword]], $row['id']);
        }
    }
    $datas = array();
    foreach ($tag_id as $tag_name => $tag_id) {
        array_push($datas, array('id' => $tag_id, 'name' => $tag_name, 'url_name' => str2url($tag_name)));
    }
    if (!empty($datas)) {
        mass_inserts(PREFIX_TABLE . 'tags', array_keys($datas[0]), $datas);
    }
    $datas = array();
    foreach ($tag_images as $tag_id => $images) {
        foreach (array_unique($images) as $image_id) {
            array_push($datas, array('tag_id' => $tag_id, 'image_id' => $image_id));
        }
    }
    if (!empty($datas)) {
        mass_inserts(PREFIX_TABLE . 'image_tag', array_keys($datas[0]), $datas);
    }
    //
    // Delete images.keywords
    //
    $query = '
ALTER TABLE ' . PREFIX_TABLE . 'images DROP COLUMN keywords
;';
    pwg_query($query);
    //
    // Add useful indexes
    //
    $query = '
ALTER TABLE ' . PREFIX_TABLE . 'tags
  ADD INDEX tags_i1(url_name)
;';
    pwg_query($query);
    $query = '
ALTER TABLE ' . PREFIX_TABLE . 'image_tag
  ADD INDEX image_tag_i1(tag_id)
;';
    pwg_query($query);
    // print_time('tags have replaced keywords');
}
Ejemplo n.º 18
0
/**
 * API method
 * Updates users
 * @param mixed[] $params
 *    @option int[] user_id
 *    @option string username (optional)
 *    @option string password (optional)
 *    @option string email (optional)
 *    @option string status (optional)
 *    @option int level (optional)
 *    @option string language (optional)
 *    @option string theme (optional)
 *    @option int nb_image_page (optional)
 *    @option int recent_period (optional)
 *    @option bool expand (optional)
 *    @option bool show_nb_comments (optional)
 *    @option bool show_nb_hits (optional)
 *    @option bool enabled_high (optional)
 */
function ws_users_setInfo($params, &$service)
{
    if (get_pwg_token() != $params['pwg_token']) {
        return new PwgError(403, 'Invalid security token');
    }
    global $conf, $user;
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    $updates = $updates_infos = array();
    $update_status = null;
    if (count($params['user_id']) == 1) {
        if (get_username($params['user_id'][0]) === false) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'This user does not exist.');
        }
        if (!empty($params['username'])) {
            $user_id = get_userid($params['username']);
            if ($user_id and $user_id != $params['user_id'][0]) {
                return new PwgError(WS_ERR_INVALID_PARAM, l10n('this login is already used'));
            }
            if ($params['username'] != strip_tags($params['username'])) {
                return new PwgError(WS_ERR_INVALID_PARAM, l10n('html tags are not allowed in login'));
            }
            $updates[$conf['user_fields']['username']] = $params['username'];
        }
        if (!empty($params['email'])) {
            if (($error = validate_mail_address($params['user_id'][0], $params['email'])) != '') {
                return new PwgError(WS_ERR_INVALID_PARAM, $error);
            }
            $updates[$conf['user_fields']['email']] = $params['email'];
        }
        if (!empty($params['password'])) {
            $updates[$conf['user_fields']['password']] = $conf['password_hash']($params['password']);
        }
    }
    if (!empty($params['status'])) {
        if (in_array($params['status'], array('webmaster', 'admin')) and !is_webmaster()) {
            return new PwgError(403, 'Only webmasters can grant "webmaster/admin" status');
        }
        if (!in_array($params['status'], array('guest', 'generic', 'normal', 'admin', 'webmaster'))) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid status');
        }
        $protected_users = array($user['id'], $conf['guest_id'], $conf['webmaster_id']);
        // an admin can't change status of other admin/webmaster
        if ('admin' == $user['status']) {
            $query = '
SELECT
    user_id
  FROM ' . USER_INFOS_TABLE . '
  WHERE status IN (\'webmaster\', \'admin\')
;';
            $protected_users = array_merge($protected_users, query2array($query, null, 'user_id'));
        }
        // status update query is separated from the rest as not applying to the same
        // set of users (current, guest and webmaster can't be changed)
        $params['user_id_for_status'] = array_diff($params['user_id'], $protected_users);
        $update_status = $params['status'];
    }
    if (!empty($params['level']) or @$params['level'] === 0) {
        if (!in_array($params['level'], $conf['available_permission_levels'])) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid level');
        }
        $updates_infos['level'] = $params['level'];
    }
    if (!empty($params['language'])) {
        if (!in_array($params['language'], array_keys(get_languages()))) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid language');
        }
        $updates_infos['language'] = $params['language'];
    }
    if (!empty($params['theme'])) {
        if (!in_array($params['theme'], array_keys(get_pwg_themes()))) {
            return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid theme');
        }
        $updates_infos['theme'] = $params['theme'];
    }
    if (!empty($params['nb_image_page'])) {
        $updates_infos['nb_image_page'] = $params['nb_image_page'];
    }
    if (!empty($params['recent_period']) or @$params['recent_period'] === 0) {
        $updates_infos['recent_period'] = $params['recent_period'];
    }
    if (!empty($params['expand']) or @$params['expand'] === false) {
        $updates_infos['expand'] = boolean_to_string($params['expand']);
    }
    if (!empty($params['show_nb_comments']) or @$params['show_nb_comments'] === false) {
        $updates_infos['show_nb_comments'] = boolean_to_string($params['show_nb_comments']);
    }
    if (!empty($params['show_nb_hits']) or @$params['show_nb_hits'] === false) {
        $updates_infos['show_nb_hits'] = boolean_to_string($params['show_nb_hits']);
    }
    if (!empty($params['enabled_high']) or @$params['enabled_high'] === false) {
        $updates_infos['enabled_high'] = boolean_to_string($params['enabled_high']);
    }
    // perform updates
    single_update(USERS_TABLE, $updates, array($conf['user_fields']['id'] => $params['user_id'][0]));
    if (isset($update_status) and count($params['user_id_for_status']) > 0) {
        $query = '
UPDATE ' . USER_INFOS_TABLE . ' SET
    status = "' . $update_status . '"
  WHERE user_id IN(' . implode(',', $params['user_id_for_status']) . ')
;';
        pwg_query($query);
    }
    if (count($updates_infos) > 0) {
        $query = '
UPDATE ' . USER_INFOS_TABLE . ' SET ';
        $first = true;
        foreach ($updates_infos as $field => $value) {
            if (!$first) {
                $query .= ', ';
            } else {
                $first = false;
            }
            $query .= $field . ' = "' . $value . '"';
        }
        $query .= '
  WHERE user_id IN(' . implode(',', $params['user_id']) . ')
;';
        pwg_query($query);
    }
    // manage association to groups
    if (!empty($params['group_id'])) {
        $query = '
DELETE
  FROM ' . USER_GROUP_TABLE . '
  WHERE user_id IN (' . implode(',', $params['user_id']) . ')
;';
        pwg_query($query);
        // we remove all provided groups that do not really exist
        $query = '
SELECT
    id
  FROM ' . GROUPS_TABLE . '
  WHERE id IN (' . implode(',', $params['group_id']) . ')
;';
        $group_ids = array_from_query($query, 'id');
        // if only -1 (a group id that can't exist) is in the list, then no
        // group is associated
        if (count($group_ids) > 0) {
            $inserts = array();
            foreach ($group_ids as $group_id) {
                foreach ($params['user_id'] as $user_id) {
                    $inserts[] = array('user_id' => $user_id, 'group_id' => $group_id);
                }
            }
            mass_inserts(USER_GROUP_TABLE, array_keys($inserts[0]), $inserts);
        }
    }
    invalidate_user_cache();
    return $service->invoke('pwg.users.getList', array('user_id' => $params['user_id'], 'display' => 'basics,' . implode(',', array_keys($updates_infos))));
}
Ejemplo n.º 19
0
/**
 * updates multiple lines in a table
 *
 * @param string table_name
 * @param array dbfields
 * @param array datas
 * @param int flags - if MASS_UPDATES_SKIP_EMPTY - empty values do not overwrite existing ones
 * @return void
 */
function mass_updates($tablename, $dbfields, $datas, $flags = 0)
{
    if (count($datas) == 0) {
        return;
    }
    // depending on the MySQL version, we use the multi table update or N update queries
    if (count($datas) < 10) {
        foreach ($datas as $data) {
            $query = '
UPDATE ' . $tablename . '
  SET ';
            $is_first = true;
            foreach ($dbfields['update'] as $key) {
                $separator = $is_first ? '' : ",\n    ";
                if (isset($data[$key]) and $data[$key] != '') {
                    $query .= $separator . $key . ' = \'' . $data[$key] . '\'';
                } else {
                    if ($flags & MASS_UPDATES_SKIP_EMPTY) {
                        continue;
                    }
                    // next field
                    $query .= "{$separator}{$key} = NULL";
                }
                $is_first = false;
            }
            if (!$is_first) {
                // only if one field at least updated
                $query .= '
  WHERE ';
                $is_first = true;
                foreach ($dbfields['primary'] as $key) {
                    if (!$is_first) {
                        $query .= ' AND ';
                    }
                    if (isset($data[$key])) {
                        $query .= $key . ' = \'' . $data[$key] . '\'';
                    } else {
                        $query .= $key . ' IS NULL';
                    }
                    $is_first = false;
                }
                pwg_query($query);
            }
        }
        // foreach update
    } else {
        // creation of the temporary table
        $query = '
SHOW FULL COLUMNS FROM ' . $tablename;
        $result = pwg_query($query);
        $columns = array();
        $all_fields = array_merge($dbfields['primary'], $dbfields['update']);
        while ($row = pwg_db_fetch_assoc($result)) {
            if (in_array($row['Field'], $all_fields)) {
                $column = $row['Field'];
                $column .= ' ' . $row['Type'];
                $nullable = true;
                if (!isset($row['Null']) or $row['Null'] == '' or $row['Null'] == 'NO') {
                    $column .= ' NOT NULL';
                    $nullable = false;
                }
                if (isset($row['Default'])) {
                    $column .= " default '" . $row['Default'] . "'";
                } elseif ($nullable) {
                    $column .= " default NULL";
                }
                if (isset($row['Collation']) and $row['Collation'] != 'NULL') {
                    $column .= " collate '" . $row['Collation'] . "'";
                }
                $columns[] = $column;
            }
        }
        $temporary_tablename = $tablename . '_' . micro_seconds();
        $query = '
CREATE TABLE ' . $temporary_tablename . '
(
  ' . implode(",\n  ", $columns) . ',
  UNIQUE KEY the_key (' . implode(',', $dbfields['primary']) . ')
)';
        pwg_query($query);
        mass_inserts($temporary_tablename, $all_fields, $datas);
        if ($flags & MASS_UPDATES_SKIP_EMPTY) {
            $func_set = create_function('$s', 'return "t1.$s = IFNULL(t2.$s, t1.$s)";');
        } else {
            $func_set = create_function('$s', 'return "t1.$s = t2.$s";');
        }
        // update of images table by joining with temporary table
        $query = '
UPDATE ' . $tablename . ' AS t1, ' . $temporary_tablename . ' AS t2
  SET ' . implode("\n    , ", array_map($func_set, $dbfields['update'])) . '
  WHERE ' . implode("\n    AND ", array_map(create_function('$s', 'return "t1.$s = t2.$s";'), $dbfields['primary']));
        pwg_query($query);
        $query = '
DROP TABLE ' . $temporary_tablename;
        pwg_query($query);
    }
}
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
0
foreach ($queries as $query) {
    $query = str_replace('piwigo_', PREFIX_TABLE, $query);
    pwg_query($query);
}
// user datas migration from piwigo_users to piwigo_user_infos
$query = '
SELECT *
  FROM ' . USERS_TABLE . '
;';
$datas = array();
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result)) {
    $row['user_id'] = $row['id'];
    $row['registration_date'] = $dbnow;
    array_push($datas, $row);
}
include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
mass_inserts(USER_INFOS_TABLE, array('user_id', 'nb_image_line', 'nb_line_page', 'status', 'language', 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', 'recent_period', 'template', 'registration_date'), $datas);
$queries = array("\nUPDATE " . USER_INFOS_TABLE . "\n  SET template = 'yoga'\n;", "\nUPDATE " . USER_INFOS_TABLE . "\n  SET language = 'en_UK.iso-8859-1'\n  WHERE language NOT IN ('en_UK.iso-8859-1', 'fr_FR.iso-8859-1')\n;", "\nUPDATE " . CONFIG_TABLE . "\n  SET value = 'en_UK.iso-8859-1'\n  WHERE param = 'default_language'\n    AND value NOT IN ('en_UK.iso-8859-1', 'fr_FR.iso-8859-1')\n;", "\nUPDATE " . CONFIG_TABLE . "\n  SET value = 'yoga'\n  WHERE param = 'default_template'\n;", "\nINSERT INTO " . CONFIG_TABLE . "\n  (param,value,comment)\n  VALUES\n  (\n    'gallery_title',\n    'Piwigo demonstration site',\n    'Title at top of each page and for RSS feed'\n  )\n;", "\nINSERT INTO " . CONFIG_TABLE . "\n  (param,value,comment)\n  VALUES\n  (\n    'gallery_description',\n    'My photos web site',\n    'Short description displayed with gallery title'\n  )\n;");
foreach ($queries as $query) {
    $query = str_replace('piwigo_', PREFIX_TABLE, $query);
    pwg_query($query);
}
if ($prefix_thumbnail != 'TN-') {
    array_push($page['infos'], 'the thumbnail prefix configuration parameter was moved to configuration
file, copy config.inc.php from "tools" directory to "local/config" directory
and edit $conf[\'prefix_thumbnail\'] = ' . $prefix_thumbnail);
}
// now we upgrade from 1.5.0 to 1.6.0
include_once PHPWG_ROOT_PATH . 'install/upgrade_1.5.0.php';
Ejemplo n.º 22
0
/**
 * Grant access to a list of categories for a list of users.
 *
 * @param int[] $category_ids
 * @param int[] $user_ids
 */
function add_permission_on_category($category_ids, $user_ids)
{
    if (!is_array($category_ids)) {
        $category_ids = array($category_ids);
    }
    if (!is_array($user_ids)) {
        $user_ids = array($user_ids);
    }
    // check for emptiness
    if (count($category_ids) == 0 or count($user_ids) == 0) {
        return;
    }
    // make sure categories are private and select uppercats or subcats
    $cat_ids = get_uppercat_ids($category_ids);
    if (isset($_POST['apply_on_sub'])) {
        $cat_ids = array_merge($cat_ids, get_subcat_ids($category_ids));
    }
    $query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (' . implode(',', $cat_ids) . ')
    AND status = \'private\'
;';
    $private_cats = query2array($query, null, 'id');
    if (count($private_cats) == 0) {
        return;
    }
    $inserts = array();
    foreach ($private_cats as $cat_id) {
        foreach ($user_ids as $user_id) {
            $inserts[] = array('user_id' => $user_id, 'cat_id' => $cat_id);
        }
    }
    mass_inserts(USER_ACCESS_TABLE, array('user_id', 'cat_id'), $inserts, array('ignore' => true));
}
Ejemplo n.º 23
0
  FROM ' . PREFIX_TABLE . 'upgrade
;';
$applied = array_from_query($query, 'id');
// retrieve existing upgrades
$existing = get_available_upgrade_ids();
// which upgrades need to be applied?
$to_apply = array_diff($existing, $applied);
$inserts = array();
foreach ($to_apply as $upgrade_id) {
    if ($upgrade_id >= 112) {
        break;
    }
    array_push($inserts, array('id' => $upgrade_id, 'applied' => CURRENT_DATE, 'description' => '[migration from 2.3.0 to ' . PHPWG_VERSION . '] not applied'));
}
if (!empty($inserts)) {
    mass_inserts('`' . UPGRADE_TABLE . '`', array_keys($inserts[0]), $inserts);
}
// +-----------------------------------------------------------------------+
// |                          Perform upgrades                             |
// +-----------------------------------------------------------------------+
ob_start();
echo '<pre>';
for ($upgrade_id = 112; $upgrade_id <= 127; $upgrade_id++) {
    if (!file_exists(UPGRADES_PATH . '/' . $upgrade_id . '-database.php')) {
        continue;
    }
    // maybe the upgrade task has already been applied in a previous and
    // incomplete upgrade
    if (in_array($upgrade_id, $applied)) {
        continue;
    }
Ejemplo n.º 24
0
        $authorized_ids = array();
        $query = '
SELECT cat_id
  FROM ' . GROUP_ACCESS_TABLE . '
  WHERE group_id = ' . $page['group'] . '
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            $authorized_ids[] = $row['cat_id'];
        }
        $inserts = array();
        $to_autorize_ids = array_diff($private_uppercats, $authorized_ids);
        foreach ($to_autorize_ids as $to_autorize_id) {
            $inserts[] = array('group_id' => $page['group'], 'cat_id' => $to_autorize_id);
        }
        mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $inserts);
        invalidate_user_cache();
    }
}
// +-----------------------------------------------------------------------+
// |                             template init                             |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('group_perm' => 'group_perm.tpl', 'double_select' => 'double_select.tpl'));
$template->assign(array('TITLE' => l10n('Manage permissions for group "%s"', get_groupname($page['group'])), 'L_CAT_OPTIONS_TRUE' => l10n('Authorized'), 'L_CAT_OPTIONS_FALSE' => l10n('Forbidden'), 'F_ACTION' => get_root_url() . 'admin.php?page=group_perm&amp;group_id=' . $page['group']));
// only private categories are listed
$query_true = '
SELECT id,name,uppercats,global_rank
  FROM ' . CATEGORIES_TABLE . ' INNER JOIN ' . GROUP_ACCESS_TABLE . ' ON cat_id = id
  WHERE status = \'private\'
    AND group_id = ' . $page['group'] . '
;';
Ejemplo n.º 25
0
                $cat_ids = array_merge($cat_ids, get_subcat_ids(array($page['cat'])));
            }
            $query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (' . implode(',', $cat_ids) . ')
    AND status = \'private\'
;';
            $private_cats = array_from_query($query, 'id');
            $inserts = array();
            foreach ($private_cats as $cat_id) {
                foreach ($grant_groups as $group_id) {
                    $inserts[] = array('group_id' => $group_id, 'cat_id' => $cat_id);
                }
            }
            mass_inserts(GROUP_ACCESS_TABLE, array('group_id', 'cat_id'), $inserts, array('ignore' => true));
        }
        //
        // users
        //
        $query = '
SELECT user_id
  FROM ' . USER_ACCESS_TABLE . '
  WHERE cat_id = ' . $page['cat'] . '
;';
        $users_granted = array_from_query($query, 'user_id');
        if (!isset($_POST['users'])) {
            $_POST['users'] = array();
        }
        //
        // remove permissions to users
Ejemplo n.º 26
0
// | 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 = 'Add upload form parameters in database';
global $conf;
load_conf_from_db();
$upload_form_config = array('websize_resize' => true, 'websize_maxwidth' => 800, 'websize_maxheight' => 600, 'websize_quality' => 95, 'thumb_maxwidth' => 128, 'thumb_maxheight' => 96, 'thumb_quality' => 95, 'thumb_crop' => false, 'thumb_follow_orientation' => true, 'hd_keep' => true, 'hd_resize' => false, 'hd_maxwidth' => 2000, 'hd_maxheight' => 2000, 'hd_quality' => 95);
$inserts = array();
foreach ($upload_form_config as $param_shortname => $param) {
    $param_name = 'upload_form_' . $param_shortname;
    if (!isset($conf[$param_name])) {
        $conf[$param_name] = $param;
        array_push($inserts, array('param' => $param_name, 'value' => boolean_to_string($param)));
    }
}
if (count($inserts) > 0) {
    mass_inserts(CONFIG_TABLE, array_keys($inserts[0]), $inserts);
}
echo "\n" . $upgrade_description . "\n";
Ejemplo n.º 27
0
        $insert = array('id' => 1, 'galleries_url' => PHPWG_ROOT_PATH . 'galleries/');
        mass_inserts(SITES_TABLE, array_keys($insert), array($insert));
        // webmaster admin user
        $inserts = array(array('id' => 1, 'username' => $admin_name, 'password' => md5($admin_pass1), 'mail_address' => $admin_mail), array('id' => 2, 'username' => 'guest'));
        mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts);
        create_user_infos(array(1, 2), array('language' => $language));
        // Available upgrades must be ignored after a fresh installation. To
        // make PWG avoid upgrading, we must tell it upgrades have already been
        // made.
        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
        define('CURRENT_DATE', $dbnow);
        $datas = array();
        foreach (get_available_upgrade_ids() as $upgrade_id) {
            $datas[] = array('id' => $upgrade_id, 'applied' => CURRENT_DATE, 'description' => 'upgrade included in installation');
        }
        mass_inserts(UPGRADE_TABLE, array_keys($datas[0]), $datas);
        if ($is_newsletter_subscribe) {
            fetchRemote(get_newsletter_subscribe_base_url($language) . $admin_mail, $result, array(), array('origin' => 'installation'));
        }
    }
}
//------------------------------------------------------ start template output
foreach ($languages->fs_languages as $language_code => $fs_language) {
    if ($language == $language_code) {
        $template->assign('language_selection', $language_code);
    }
    $languages_options[$language_code] = $fs_language['name'];
}
$template->assign('language_options', $languages_options);
$template->assign(array('T_CONTENT_ENCODING' => 'utf-8', 'RELEASE' => PHPWG_VERSION, 'F_ACTION' => 'install.php?language=' . $language, 'F_DB_HOST' => $dbhost, 'F_DB_USER' => $dbuser, 'F_DB_NAME' => $dbname, 'F_DB_PREFIX' => $prefixeTable, 'F_ADMIN' => $admin_name, 'F_ADMIN_EMAIL' => $admin_mail, 'EMAIL' => '<span class="adminEmail">' . $admin_mail . '</span>', 'F_NEWSLETTER_SUBSCRIBE' => $is_newsletter_subscribe, 'L_INSTALL_HELP' => l10n('Need help ? Ask your question on <a href="%s">Piwigo message board</a>.', PHPWG_URL . '/forum')));
//------------------------------------------------------ errors & infos display
Ejemplo n.º 28
0
        }
    }
    if (!$simulate) {
        // inserts all new elements
        if (count($inserts) > 0) {
            mass_inserts(IMAGES_TABLE, array_keys($inserts[0]), $inserts);
            // inserts all links between new elements and their storage category
            mass_inserts(IMAGE_CATEGORY_TABLE, array_keys($insert_links[0]), $insert_links);
            // add new photos to caddie
            if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1) {
                fill_caddie($caddiables);
            }
        }
        // inserts all formats
        if (count($insert_formats) > 0) {
            mass_inserts(IMAGE_FORMAT_TABLE, array_keys($insert_formats[0]), $insert_formats);
        }
        if (count($formats_to_delete) > 0) {
            $query = '
DELETE
  FROM ' . IMAGE_FORMAT_TABLE . '
  WHERE format_id IN (' . implode(',', $formats_to_delete) . ')
;';
            pwg_query($query);
        }
    }
    $counts['new_elements'] = count($inserts);
    // delete elements that are in database but not in the filesystem
    $to_delete_elements = array();
    foreach (array_diff($db_elements, array_keys($fs)) as $path) {
        $to_delete_elements[] = array_search($path, $db_elements);