本文整理汇总了PHP中mass_inserts函数的典型用法代码示例。如果您正苦于以下问题:PHP mass_inserts函数的具体用法?PHP mass_inserts怎么用?PHP mass_inserts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mass_inserts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: NBMS_Save_Profile
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);
}
}
示例2: update_user
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));
}
}
示例3: array
}
$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) {
示例4: unset
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])) {
示例5: create_user_infos
/**
* 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);
}
}
示例6: pwg_query
$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
示例7: ws_caddie_add
/**
* 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);
}
示例8: fill_caddie
/**
* 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);
}
}
示例9: ws_permissions_add
/**
* 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']));
}
示例10: insert_new_data_user_mail_notification
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...'));
}
}
}
}
示例11: die
// | 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');
示例12: ws_groups_addUser
/**
* 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']));
}
示例13: foreach
}
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) {
示例14: hash_from_query
<?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
}
示例15: array_from_query
$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