onokazu
onoka****@users*****
2005年 6月 11日 (土) 11:32:50 JST
Index: xoops2jp/html/modules/system/admin/avatars/main.php diff -u xoops2jp/html/modules/system/admin/avatars/main.php:1.2 xoops2jp/html/modules/system/admin/avatars/main.php:1.3 --- xoops2jp/html/modules/system/admin/avatars/main.php:1.2 Fri Mar 18 21:52:38 2005 +++ xoops2jp/html/modules/system/admin/avatars/main.php Sat Jun 11 11:32:49 2005 @@ -1,5 +1,5 @@ <?php -// $Id: main.php,v 1.2 2005/03/18 12:52:38 onokazu Exp $ +// $Id: main.php,v 1.3 2005/06/11 02:32:49 onokazu Exp $ // ------------------------------------------------------------------------ // // XOOPS - PHP Content Management System // // Copyright (c) 2000 XOOPS.org // @@ -30,191 +30,215 @@ // ------------------------------------------------------------------------- // if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { - exit("Access Denied"); + exit("Access Denied"); } else { - $op = 'list'; - if (isset($_POST)) { - foreach ( $_POST as $k => $v ) { - ${$k} = $v; - } - } - if (isset($_GET['op'])) { - $op = trim($_GET['op']); - } - if ($op == 'list') { - xoops_cp_header(); - echo '<h4 style="text-align:left">'._MD_AVATARMAN.'</h4>'; - $avt_handler =& xoops_gethandler('avatar'); - $savatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'S')); - $cavatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'C')); - echo '<ul><li>'._MD_SYSAVATARS.' ('.sprintf(_NUMIMAGES, '<b>'.$savatar_count.'</b>').') [<a href="admin.php?fct=avatars&op=listavt&type=S">'._LIST.'</a>]</li><li>'._MD_CSTAVATARS.' ('.sprintf(_NUMIMAGES, '<b>'.$cavatar_count.'</b>').') [<a href="admin.php?fct=avatars&op=listavt&type=C">'._LIST.'</a>]</li></ul>'; - include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; - $form = new XoopsThemeForm(_MD_ADDAVT, 'avatar_form', 'admin.php'); - $form->setExtra('enctype="multipart/form-data"'); - $form->addElement(new XoopsFormText(_IMAGENAME, 'avatar_name', 50, 255), true); - $form->addElement(new XoopsFormFile(_IMAGEFILE, 'avatar_file', 500000)); - $form->addElement(new XoopsFormText(_IMGWEIGHT, 'avatar_weight', 3, 4, 0)); - $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'avatar_display', 1, _YES, _NO)); - $form->addElement(new XoopsFormHidden('op', 'addfile')); - $form->addElement(new XoopsFormHidden('fct', 'avatars')); - $form->addElement(new XoopsFormButton('', 'avt_button', _SUBMIT, 'submit')); - $form->display(); - xoops_cp_footer(); - exit(); - } - - if ($op == 'listavt') { - $avt_handler =& xoops_gethandler('avatar'); - xoops_cp_header(); - $type = (isset($_GET['type']) && $_GET['type'] == 'C') ? 'C' : 'S'; - echo '<a href="admin.php?fct=avatars">'. _MD_AVATARMAN .'</a> <span style="font-weight:bold;">»»</span> '; - if ($type == 'S') { - echo _MD_SYSAVATARS; - } else { - echo _MD_CSTAVATARS; - } - echo '<br /><br />'; - $criteria = new Criteria('avatar_type', $type); - $avtcount = $avt_handler->getCount($criteria); - $start = isset($_GET['start']) ? intval($_GET['start']) : 0; - $criteria->setStart($start); - $criteria->setLimit(10); - $avatars =& $avt_handler->getObjects($criteria, true); - if ($type == 'S') { - foreach (array_keys($avatars) as $i) { - echo '<form action="admin.php" method="post">'; - $id = $avatars[$i]->getVar('avatar_id'); - echo '<table class="outer" cellspacing="1" width="100%"><tr><td align="center" width="30%" rowspan="6"><img src="'.XOOPS_UPLOAD_URL.'/'.$avatars[$i]->getVar('avatar_file').'" alt="" /></td><td class="head">'._IMAGENAME,'</td><td class="even"><input type="hidden" name="avatar_id[]" value="'.$id.'" /><input type="text" name="avatar_name[]" value="'.$avatars[$i]->getVar('avatar_name', 'E').'" size="20" maxlength="255" /></td></tr><tr><td class="head">'._IMAGEMIME.'</td><td class="odd">'.$avatars[$i]->getVar('avatar_mimetype').'</td></tr><tr><td class="head">'._MD_USERS.'</td><td class="even">'.$avatars[$i]->getUserCount().'</td></tr><tr><td class="head">'._IMGWEIGHT.'</td><td class="odd"><input type="text" name="avatar_weight[]" value="'.$avatars[$i]->getVar('avatar_weight').'" size="3" maxlength="4" /></td></tr><tr><td class="head">'._IMGDISPLAY.'</td><td class="even"><input type="checkbox" name="avatar_display[]" value="1"'; - if ($avatars[$i]->getVar('avatar_display') == 1) { - echo ' checked="checked"'; - } - echo ' /></td></tr><tr><td class="head"> </td><td class="even"><a href="admin.php?fct=avatars&op=delfile&avatar_id='.$id.'">'._DELETE.'</a></td></tr></table><br />'; - } - } else { - foreach (array_keys($avatars) as $i) { - echo '<table cellspacing="1" class="outer" width="100%"><tr><td width="30%" rowspan="6" align="center"><img src="'.XOOPS_UPLOAD_URL.'/'.$avatars[$i]->getVar('avatar_file').'" alt="" /></td><td class="head">'._IMAGENAME,'</td><td class="even"><a href="'.XOOPS_URL.'/userinfo.php?uid='; - $userids =& $avt_handler->getUser($avatars[$i]); - echo $userids[0].'">'.$avatars[$i]->getVar('avatar_name').'</a></td></tr><tr><td class="head">'._IMAGEMIME.'</td><td class="odd">'.$avatars[$i]->getVar('avatar_mimetype').'</td></tr><tr><td class="head"> </td><td align="center" class="even"><a href="admin.php?fct=avatars&op=delfile&avatar_id='.$avatars[$i]->getVar('avatar_id').'&user_id='.$userids[0].'">'._DELETE.'</a></td></tr></table><br />'; - } - } - if ($avtcount > 0) { - if ($avtcount > 10) { - include_once XOOPS_ROOT_PATH.'/class/pagenav.php'; - $nav = new XoopsPageNav($avtcount, 10, $start, 'start', 'fct=avatars&type='.$type.'&op=listavt'); - echo '<div style="text-align:right;">'.$nav->renderImageNav().'</div>'; - } - if ($type == 'S') { - echo '<div style="text-align:center;"><input type="hidden" name="op" value="save" /><input type="hidden" name="fct" value="avatars" /><input type="submit" name="submit" value="'._SUBMIT.'" /></div></form>'; - } - } - xoops_cp_footer(); - exit(); - } - - if ($op == 'save') { - $count = count($avatar_id); - if ($count > 0) { - $avt_handler =& xoops_gethandler('avatar'); - $error = array(); - for ($i = 0; $i < $count; $i++) { - $avatar =& $avt_handler->get($avatar_id[$i]); - if (!is_object($avatar)) { - $error[] = sprintf(_FAILGETIMG, $avatar_id[$i]); - continue; - } - $avatar_display[$i] = empty($avatar_display[$i]) ? 0 : 1; - $avatar->setVar('avatar_display', $avatar_display[$i]); - $avatar->setVar('avatar_weight', $avatar_weight[$i]); - $avatar->setVar('avatar_name', $avatar_name[$i]); - if (!$avt_handler->insert($avatar)) { - $error[] = sprintf(_FAILSAVEIMG, $avatar_id[$i]); - } - unset($avatar_id[$i]); - unset($avatar_name[$i]); - unset($avatar_weight[$i]); - unset($avatar_display[$i]); - } - if (count($error) > 0) { - xoops_cp_header(); - foreach ($error as $err) { - echo $err.'<br />'; - } - xoops_cp_footer(); - exit(); - } - } - redirect_header('admin.php?fct=avatars',2,_MD_AM_DBUPDATED); - } - - if ($op == 'addfile') { - include_once XOOPS_ROOT_PATH.'/class/uploader.php'; - $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), 500000); - $uploader->setPrefix('savt'); - $err = array(); - $ucount = count($_POST['xoops_upload_file']); - for ($i = 0; $i < $ucount; $i++) { - if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) { - if (!$uploader->upload()) { - $err[] = $uploader->getErrors(); - } else { - $avt_handler =& xoops_gethandler('avatar'); - $avatar =& $avt_handler->create(); - $avatar->setVar('avatar_file', $uploader->getSavedFileName()); - $avatar->setVar('avatar_name', $avatar_name); - $avatar->setVar('avatar_mimetype', $uploader->getMediaType()); - $avatar_display = empty($avatar_display) ? 0 : 1; - $avatar->setVar('avatar_display', $avatar_display); - $avatar->setVar('avatar_weight', $avatar_weight); - $avatar->setVar('avatar_type', 'S'); - if (!$avt_handler->insert($avatar)) { - $err[] = sprintf(_FAILSAVEIMG, $avatar->getVar('avatar_name')); - } - } - } else { - $err[] = sprintf(_FAILFETCHIMG, $i); - } - } - if (count($err) > 0) { - xoops_cp_header(); - xoops_error($err); - xoops_cp_footer(); - exit(); - } - redirect_header('admin.php?fct=avatars',2,_MD_AM_DBUPDATED); - } - - if ($op == 'delfile') { - xoops_cp_header(); - $user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0; - xoops_confirm(array('op' => 'delfileok', 'avatar_id' => intval($_GET['avatar_id']), 'fct' => 'avatars', 'user_id' => $user_id), 'admin.php', _MD_RUDELIMG); - xoops_cp_footer(); - exit(); - } - - if ($op == 'delfileok') { - $avatar_id = intval($avatar_id); - if ($avatar_id <= 0) { - redirect_header('admin.php?fct=avatars',1); - } - $avt_handler = xoops_gethandler('avatar'); - $avatar =& $avt_handler->get($avatar_id); - if (!is_object($avatar)) { - redirect_header('admin.php?fct=avatars',1); - } - if (!$avt_handler->delete($avatar)) { - xoops_cp_header(); - xoops_error(sprintf(_MD_FAILDEL, $avatar->getVar('avatar_id'))); - xoops_cp_footer(); - exit(); - } - $file = $avatar->getVar('avatar_file'); - @unlink(XOOPS_UPLOAD_PATH.'/'.$file); - if (isset($user_id) && $avatar->getVar('avatar_type') == 'C') { - $xoopsDB->query("UPDATE ".$xoopsDB->prefix('users')." SET user_avatar='blank.gif' WHERE uid=".intval($user_id)); - } else { - $xoopsDB->query("UPDATE ".$xoopsDB->prefix('users')." SET user_avatar='blank.gif' WHERE user_avatar='".$file."'"); - } - redirect_header('admin.php?fct=avatars',2,_MD_AM_DBUPDATED); - } + $op = 'list'; + if (isset($_GET['op'])) { + $op = trim($_GET['op']); + } elseif (isset($_POST['op'])) { + $op = trim($_POST['op']); + } + if ($op == 'list') { + xoops_cp_header(); + echo '<h4 style="text-align:left">'._MD_AVATARMAN.'</h4>'; + $avt_handler =& xoops_gethandler('avatar'); + $savatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'S')); + $cavatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'C')); + echo '<ul><li>'._MD_SYSAVATARS.' ('.sprintf(_NUMIMAGES, '<b>'.$savatar_count.'</b>').') [<a href="admin.php?fct=avatars&op=listavt&type=S">'._LIST.'</a>]</li><li>'._MD_CSTAVATARS.' ('.sprintf(_NUMIMAGES, '<b>'.$cavatar_count.'</b>').') [<a href="admin.php?fct=avatars&op=listavt&type=C">'._LIST.'</a>]</li></ul>'; + include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; + $form = new XoopsThemeForm(_MD_ADDAVT, 'avatar_form', 'admin.php'); + $form->setExtra('enctype="multipart/form-data"'); + $form->addElement(new XoopsFormToken(XoopsMultiTokenHandler::quickCreate('avatars_addfile'))); + $form->addElement(new XoopsFormText(_IMAGENAME, 'avatar_name', 50, 255), true); + $form->addElement(new XoopsFormFile(_IMAGEFILE, 'avatar_file', 500000)); + $form->addElement(new XoopsFormText(_IMGWEIGHT, 'avatar_weight', 3, 4, 0)); + $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'avatar_display', 1, _YES, _NO)); + $form->addElement(new XoopsFormHidden('op', 'addfile')); + $form->addElement(new XoopsFormHidden('fct', 'avatars')); + $form->addElement(new XoopsFormButton('', 'avt_button', _SUBMIT, 'submit')); + $form->display(); + xoops_cp_footer(); + exit(); + } + + if ($op == 'listavt') { + $avt_handler =& xoops_gethandler('avatar'); + xoops_cp_header(); + $type = (isset($_GET['type']) && $_GET['type'] == 'C') ? 'C' : 'S'; + echo '<a href="admin.php?fct=avatars">'. _MD_AVATARMAN .'</a> <span style="font-weight:bold;">»»</span> '; + if ($type == 'S') { + echo _MD_SYSAVATARS; + } else { + echo _MD_CSTAVATARS; + } + echo '<br /><br />'; + $criteria = new Criteria('avatar_type', $type); + $avtcount = $avt_handler->getCount($criteria); + $start = isset($_GET['start']) ? intval($_GET['start']) : 0; + $criteria->setStart($start); + $criteria->setLimit(10); + $avatars =& $avt_handler->getObjects($criteria, true); + + $token =& XoopsMultiTokenHandler::quickCreate('avatars_save'); + + if ($type == 'S') { + foreach (array_keys($avatars) as $i) { + echo '<form action="admin.php" method="post">'; + echo $token->getHtml(); + $id = $avatars[$i]->getVar('avatar_id'); + echo '<table class="outer" cellspacing="1" width="100%"><tr><td align="center" width="30%" rowspan="6"><img src="'.XOOPS_UPLOAD_URL.'/'.$avatars[$i]->getVar('avatar_file').'" alt="" /></td><td class="head">'._IMAGENAME,'</td><td class="even"><input type="hidden" name="avatar_id[]" value="'.$id.'" /><input type="text" name="avatar_name[]" value="'.$avatars[$i]->getVar('avatar_name', 'E').'" size="20" maxlength="255" /></td></tr><tr><td class="head">'._IMAGEMIME.'</td><td class="odd">'.$avatars[$i]->getVar('avatar_mimetype').'</td></tr><tr><td class="head">'._MD_USERS.'</td><td class="even">'.$avatars[$i]->getUserCount().'</td></tr><tr><td class="head">'._IMGWEIGHT.'</td><td class="odd"><input type="text" name="avatar_weight[]" value="'.$avatars[$i]->getVar('avatar_weight').'" size="3" maxlength="4" /></td></tr><tr><td class="head">'._IMGDISPLAY.'</td><td class="even"><input type="checkbox" name="avatar_display[]" value="1"'; + if ($avatars[$i]->getVar('avatar_display') == 1) { + echo ' checked="checked"'; + } + echo ' /></td></tr><tr><td class="head"> </td><td class="even"><a href="admin.php?fct=avatars&op=delfile&avatar_id='.$id.'">'._DELETE.'</a></td></tr></table><br />'; + } + } else { + foreach (array_keys($avatars) as $i) { + echo '<table cellspacing="1" class="outer" width="100%"><tr><td width="30%" rowspan="6" align="center"><img src="'.XOOPS_UPLOAD_URL.'/'.$avatars[$i]->getVar('avatar_file').'" alt="" /></td><td class="head">'._IMAGENAME,'</td><td class="even"><a href="'.XOOPS_URL.'/userinfo.php?uid='; + $userids =& $avt_handler->getUser($avatars[$i]); + echo $userids[0].'">'.$avatars[$i]->getVar('avatar_name').'</a></td></tr><tr><td class="head">'._IMAGEMIME.'</td><td class="odd">'.$avatars[$i]->getVar('avatar_mimetype').'</td></tr><tr><td class="head"> </td><td align="center" class="even"><a href="admin.php?fct=avatars&op=delfile&avatar_id='.$avatars[$i]->getVar('avatar_id').'&user_id='.$userids[0].'">'._DELETE.'</a></td></tr></table><br />'; + } + } + if ($avtcount > 0) { + if ($avtcount > 10) { + include_once XOOPS_ROOT_PATH.'/class/pagenav.php'; + $nav = new XoopsPageNav($avtcount, 10, $start, 'start', 'fct=avatars&type='.$type.'&op=listavt'); + echo '<div style="text-align:right;">'.$nav->renderImageNav().'</div>'; + } + if ($type == 'S') { + echo '<div style="text-align:center;"><input type="hidden" name="op" value="save" /><input type="hidden" name="fct" value="avatars" /><input type="submit" name="submit" value="'._SUBMIT.'" /></div></form>'; + } + } + xoops_cp_footer(); + exit(); + } + + if ($op == 'save') { + if(!XoopsMultiTokenHandler::quickValidate('avatars_save')) { + xoops_cp_header(); + xoops_error('Ticket Error'); + xoops_cp_footer(); + exit(); + } + + $count = count($_POST['avatar_id']); + if ($count > 0) { + $avt_handler =& xoops_gethandler('avatar'); + $error = array(); + for ($i = 0; $i < $count; $i++) { + $avatar =& $avt_handler->get($_POST['avatar_id'][$i]); + if (!is_object($avatar)) { + $error[] = sprintf(_FAILGETIMG, $_POST['avatar_id'][$i]); + continue; + } + $avatar_display[$i] = empty($_POST['avatar_display'][$i]) ? 0 : 1; + $avatar->setVar('avatar_display', $avatar_display[$i]); + $avatar->setVar('avatar_weight', $_POST['avatar_weight'][$i]); + $avatar->setVar('avatar_name', $_POST['avatar_name'][$i]); + if (!$avt_handler->insert($avatar)) { + $error[] = sprintf(_FAILSAVEIMG, $_POST['avatar_id'][$i]); + } + unset($avatar_id[$i]); + unset($avatar_name[$i]); + unset($avatar_weight[$i]); + unset($avatar_display[$i]); + } + if (count($error) > 0) { + xoops_cp_header(); + foreach ($error as $err) { + echo $err.'<br />'; + } + xoops_cp_footer(); + exit(); + } + } + redirect_header('admin.php?fct=avatars',2,_MD_AM_DBUPDATED); + } + + if ($op == 'addfile') { + if(!XoopsMultiTokenHandler::quickValidate('avatars_addfile')) { + xoops_cp_header(); + xoops_error('Ticket Error'); + xoops_cp_footer(); + exit(); + } + + include_once XOOPS_ROOT_PATH.'/class/uploader.php'; + $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), 500000); + $uploader->setAllowedExtensions(array('gif', 'jpeg', 'jpg', 'png')); + $uploader->setPrefix('savt'); + $err = array(); + $ucount = count($_POST['xoops_upload_file']); + for ($i = 0; $i < $ucount; $i++) { + if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) { + if (!$uploader->upload()) { + $err[] = $uploader->getErrors(); + } else { + $avt_handler =& xoops_gethandler('avatar'); + $avatar =& $avt_handler->create(); + $avatar->setVar('avatar_file', $uploader->getSavedFileName()); + $avatar->setVar('avatar_name', $_POST['avatar_name']); + $avatar->setVar('avatar_mimetype', $uploader->getMediaType()); + $avatar_display = empty($_POST['avatar_display']) ? 0 : 1; + $avatar->setVar('avatar_display', $avatar_display); + $avatar->setVar('avatar_weight', $_POST['avatar_weight']); + $avatar->setVar('avatar_type', 'S'); + if (!$avt_handler->insert($avatar)) { + $err[] = sprintf(_FAILSAVEIMG, $avatar->getVar('avatar_name')); + } + } + } else { + $err[] = sprintf(_FAILFETCHIMG, $i); + } + } + if (count($err) > 0) { + xoops_cp_header(); + xoops_error($err); + xoops_cp_footer(); + exit(); + } + redirect_header('admin.php?fct=avatars',2,_MD_AM_DBUPDATED); + } + + if ($op == 'delfile') { + xoops_cp_header(); + $user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0; + xoops_token_confirm(array('op' => 'delfileok', 'avatar_id' => intval($_GET['avatar_id']), 'fct' => 'avatars', 'user_id' => $user_id), 'admin.php', _MD_RUDELIMG); + xoops_cp_footer(); + exit(); + } + + if ($op == 'delfileok') { + if(!xoops_confirm_validate()) { + xoops_cp_header(); + xoops_error("Ticket Error"); + xoops_cp_footer(); + exit(); + } + + $avatar_id = intval($_POST['avatar_id']); + if ($avatar_id <= 0) { + redirect_header('admin.php?fct=avatars',1); + } + $avt_handler = xoops_gethandler('avatar'); + $avatar =& $avt_handler->get($avatar_id); + if (!is_object($avatar)) { + redirect_header('admin.php?fct=avatars',1); + } + if (!$avt_handler->delete($avatar)) { + xoops_cp_header(); + xoops_error(sprintf(_MD_FAILDEL, $avatar->getVar('avatar_id'))); + xoops_cp_footer(); + exit(); + } + $file = $avatar->getVar('avatar_file'); + @unlink(XOOPS_UPLOAD_PATH.'/'.$file); + if (isset($user_id) && $avatar->getVar('avatar_type') == 'C') { + $xoopsDB->query("UPDATE ".$xoopsDB->prefix('users')." SET user_avatar='blank.gif' WHERE uid=".intval($user_id)); + } else { + $xoopsDB->query("UPDATE ".$xoopsDB->prefix('users')." SET user_avatar='blank.gif' WHERE user_avatar='".$file."'"); + } + redirect_header('admin.php?fct=avatars',2,_MD_AM_DBUPDATED); + } } ?> \ No newline at end of file