From f54877ca04e9e99e67b94f7c486229d4c6543a8a Mon Sep 17 00:00:00 2001 From: rub Date: Sat, 1 Mar 2008 13:23:51 +0000 Subject: 0000809: Use more php classes implementation Use class for c13y git-svn-id: http://piwigo.org/svn/trunk@2232 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/c13y_internal.class.php | 221 ++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 admin/include/c13y_internal.class.php (limited to 'admin/include/c13y_internal.class.php') diff --git a/admin/include/c13y_internal.class.php b/admin/include/c13y_internal.class.php new file mode 100644 index 000000000..64c5d4d9f --- /dev/null +++ b/admin/include/c13y_internal.class.php @@ -0,0 +1,221 @@ +add_anomaly( + sprintf(l10n('c13y_exif_anomaly'), '$conf[\''.$value.'\']'), + null, + null, + sprintf(l10n('c13y_exif_correction'), '$conf[\''.$value.'\']') + .'
'. + $c13y->get_htlm_links_more_info()); + } + } + } + + /** + * Check user + * + * @param void + * @return void + */ + function c13y_user($c13y) + { + global $conf; + + $c13y_users = array(); + $c13y_users[$conf['guest_id']] = array( + 'status' => 'guest', + 'l10n_non_existent' => 'c13y_guest_non_existent', + 'l10n_bad_status' => 'c13y_bad_guest_status'); + + if ($conf['guest_id'] != $conf['default_user_id']) + { + $c13y_users[$conf['default_user_id']] = array( + 'password' => null, + 'l10n_non_existent' => 'c13y_default_non_existent'); + } + + $c13y_users[$conf['webmaster_id']] = array( + 'status' => 'webmaster', + 'l10n_non_existent' => 'c13y_webmaster_non_existent', + 'l10n_bad_status' => 'c13y_bad_webmaster_status'); + + $query = ' + select u.'.$conf['user_fields']['id'].' as id, ui.status + from '.USERS_TABLE.' as u + left join '.USER_INFOS_TABLE.' as ui + on u.'.$conf['user_fields']['id'].' = ui.user_id + where + u.'.$conf['user_fields']['id'].' in ('.implode(',', array_keys($c13y_users)).') + ;'; + + + $status = array(); + + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $status[$row['id']] = $row['status']; + } + + foreach ($c13y_users as $id => $data) + { + if (!array_key_exists($id, $status)) + { + $c13y->add_anomaly(l10n($data['l10n_non_existent']), 'c13y_correction_user', + array('id' => $id, 'action' => 'creation')); + } + else + if (!empty($data['status']) and $status[$id] != $data['status']) + { + $c13y->add_anomaly(l10n($data['l10n_bad_status']), 'c13y_correction_user', + array('id' => $id, 'action' => 'status')); + } + } + } + + /** + * 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' => $name, + 'password' => $password + ), + ); + mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); + + create_user_infos($id); + + $page['infos'][] = sprintf(l10n('c13y_user_created'), $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('c13y_user_status_updated'), get_username($id)); + + $result = true; + } + break; + } + } + + return $result; + } +} + +?> -- cgit v1.2.3