/** * Delete a user from the system. * * This will also delete any of the user's events in the system that have * no other participants. Any layers that point to this user * will be deleted. Any views that include this user will be updated. * * @param string $user User to delete */ function user_delete_user($user) { // Get event ids for all events this user is a participant $events = get_users_event_ids($user); // Now count number of participants in each event... // If just 1, then save id to be deleted $delete_em = array(); for ($i = 0; $i < count($events); $i++) { $res = dbi_execute('SELECT COUNT(*) FROM webcal_entry_user WHERE cal_id = ?', array($events[$i])); if ($res) { if ($row = dbi_fetch_row($res)) { if ($row[0] == 1) { $delete_em[] = $events[$i]; } } dbi_free_result($res); } } // Now delete events that were just for this user for ($i = 0; $i < count($delete_em); $i++) { dbi_execute('DELETE FROM webcal_entry_repeats WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry_repeats_not WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry_log WHERE cal_entry_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_import_data WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_site_extras WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry_ext_user WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_reminders WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_blob WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry WHERE cal_id = ?', array($delete_em[$i])); } // Delete user participation from events dbi_execute('DELETE FROM webcal_entry_user WHERE cal_login = ?', array($user)); // Delete preferences dbi_execute('DELETE FROM webcal_user_pref WHERE cal_login = ?', array($user)); // Delete from groups dbi_execute('DELETE FROM webcal_group_user WHERE cal_login = ?', array($user)); // Delete bosses & assistants dbi_execute('DELETE FROM webcal_asst WHERE cal_boss = ?', array($user)); dbi_execute('DELETE FROM webcal_asst WHERE cal_assistant = ?', array($user)); // Delete user's views $delete_em = array(); $res = dbi_execute('SELECT cal_view_id FROM webcal_view WHERE cal_owner = ?', array($user)); if ($res) { while ($row = dbi_fetch_row($res)) { $delete_em[] = $row[0]; } dbi_free_result($res); } for ($i = 0; $i < count($delete_em); $i++) { dbi_execute('DELETE FROM webcal_view_user WHERE cal_view_id = ?', array($delete_em[$i])); } dbi_execute('DELETE FROM webcal_view WHERE cal_owner = ?', array($user)); //Delete them from any other user's views dbi_execute('DELETE FROM webcal_view_user WHERE cal_login = ?', array($user)); // Delete layers dbi_execute('DELETE FROM webcal_user_layers WHERE cal_login = ?', array($user)); // Delete any layers other users may have that point to this user. dbi_execute('DELETE FROM webcal_user_layers WHERE cal_layeruser = ?', array($user)); // Delete user dbi_execute('DELETE FROM webcal_user WHERE cal_login = ?', array($user)); // Delete function access dbi_execute('DELETE FROM webcal_access_function WHERE cal_login = ?', array($user)); // Delete user access dbi_execute('DELETE FROM webcal_access_user WHERE cal_login = ?', array($user)); dbi_execute('DELETE FROM webcal_access_user WHERE cal_other_user = ?', array($user)); // Delete user's categories dbi_execute('DELETE FROM webcal_categories WHERE cat_owner = ?', array($user)); dbi_execute('DELETE FROM webcal_entry_categories WHERE cat_owner = ?', array($user)); // Delete user's reports $delete_em = array(); $res = dbi_execute('SELECT cal_report_id FROM webcal_report WHERE cal_login = ?', array($user)); if ($res) { while ($row = dbi_fetch_row($res)) { $delete_em[] = $row[0]; } dbi_free_result($res); } for ($i = 0; $i < count($delete_em); $i++) { dbi_execute('DELETE FROM webcal_report_template WHERE cal_report_id = ?', array($delete_em[$i])); } dbi_execute('DELETE FROM webcal_report WHERE cal_login = ?', array($user)); //not sure about this one??? dbi_execute('DELETE FROM webcal_report WHERE cal_user = ?', array($user)); // Delete user templates dbi_execute('DELETE FROM webcal_user_template WHERE cal_login = ?', array($user)); }
$nfirstname = getValue('nfirstname'); $nlastname = getValue('nlastname'); $nadmin = getValue('nadmin'); $ispublic = getValue('ispublic'); $action = getValue('action'); $delete = getValue('delete'); if (!$is_admin) { echo print_not_auth(3, true) . print_trailer(); exit; } $error = ''; if ($action == 'Delete' || $action == translate('Delete')) { // delete this nonuser calendar $user = $nid; // Get event ids for all events this user is a participant. $events = get_users_event_ids($user); // Now count number of participants in each event... // If just 1, then save id to be deleted. $delete_em = array(); for ($i = 0, $cnt = count($events); $i < $cnt; $i++) { $res = dbi_execute('SELECT COUNT( * ) FROM webcal_entry_user WHERE cal_id = ?', array($events[$i])); if ($res) { if ($row = dbi_fetch_row($res) && $row[0] == 1) { $delete_em[] = $events[$i]; } dbi_free_result($res); } } // Now delete events that were just for this user for ($i = 0, $cnt = count($delete_em); $i < $cnt; $i++) {
function delete_events($nid) { // Get event ids for all events this user is a participant. $events = get_users_event_ids($nid); // Now count number of participants in each event... // If just 1, then save id to be deleted. $delete_em = array(); for ($i = 0, $cnt = count($events); $i < $cnt; $i++) { $res = dbi_execute('SELECT COUNT( * ) FROM webcal_entry_user WHERE cal_id = ?', array($events[$i])); if ($res) { $row = dbi_fetch_row($res); if (!empty($row) && $row[0] == 1) { $delete_em[] = $events[$i]; } dbi_free_result($res); } } // Now delete events that were just for this user. for ($i = 0, $cnt = count($delete_em); $i < $cnt; $i++) { dbi_execute('DELETE FROM webcal_entry_repeats WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry_repeats_not WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry_log WHERE cal_entry_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_import_data WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_site_extras WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry_ext_user WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_reminders WHERE cal_id =? ', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_blob WHERE cal_id = ?', array($delete_em[$i])); dbi_execute('DELETE FROM webcal_entry WHERE cal_id = ?', array($delete_em[$i])); } // Delete user participation from events. dbi_execute('DELETE FROM webcal_entry_user WHERE cal_login = ?', array($nid)); }
function user_delete_user($user) { // Get event ids for all events this user is a participant $events = get_users_event_ids($user); // Now count number of participants in each event... // If just 1, then save id to be deleted $delete_em = array(); for ($i = 0; $i < count($events); $i++) { $res = dbi_query("SELECT COUNT(*) FROM webcal_entry_user " . "WHERE cal_id = " . $events[$i]); if ($res) { if ($row = dbi_fetch_row($res)) { if ($row[0] == 1) { $delete_em[] = $events[$i]; } } dbi_free_result($res); } } // Now delete events that were just for this user for ($i = 0; $i < count($delete_em); $i++) { dbi_query("DELETE FROM webcal_entry WHERE cal_id = " . $delete_em[$i]); } // Delete user participation from events dbi_query("DELETE FROM webcal_entry_user WHERE cal_login = '******'"); // Delete preferences dbi_query("DELETE FROM webcal_user_pref WHERE cal_login = '******'"); // Delete from groups dbi_query("DELETE FROM webcal_group_user WHERE cal_login = '******'"); // Delete bosses & assistants dbi_query("DELETE FROM webcal_asst WHERE cal_boss = '{$user}'"); dbi_query("DELETE FROM webcal_asst WHERE cal_assistant = '{$user}'"); // Delete user's views $delete_em = array(); $res = dbi_query("SELECT cal_view_id FROM webcal_view " . "WHERE cal_owner = '{$user}'"); if ($res) { while ($row = dbi_fetch_row($res)) { $delete_em[] = $row[0]; } dbi_free_result($res); } for ($i = 0; $i < count($delete_em); $i++) { dbi_query("DELETE FROM webcal_view_user WHERE cal_view_id = " . $delete_em[$i]); } dbi_query("DELETE FROM webcal_view WHERE cal_owner = '{$user}'"); // Delete layers dbi_query("DELETE FROM webcal_user_layers WHERE cal_login = '******'"); // Delete any layers other users may have that point to this user. dbi_query("DELETE FROM webcal_user_layers WHERE cal_layeruser = '******'"); }
$save = getPostValue('Save'); $add = getPostValue('Add'); $delete = getPostValue('delete'); $nid = getPostValue('nid'); $nfirstname = getPostValue('nfirstname'); $nlastname = getPostValue('nlastname'); $nadmin = getPostValue('nadmin'); $old_admin = getPostValue('old_admin'); $ispublic = getPostValue('ispublic'); if (empty($ispublic)) { $ispublic = 'N'; } if (!empty($delete)) { // delete this nonuser calendar // Get event ids for all events this user is a participant $events = get_users_event_ids($nid); // Now count number of participants in each event... // If just 1, then save id to be deleted $delete_em = array(); for ($i = 0, $cnt = count($events); $i < $cnt; $i++) { $res = dbi_execute('SELECT COUNT( * ) FROM webcal_entry_user WHERE cal_id = ?', array($events[$i])); if ($res) { if ($row = dbi_fetch_row($res)) { if ($row[0] == 1) { $delete_em[] = $events[$i]; } } dbi_free_result($res); } }