fetch_all_data() as $medal) {
$checkavailable = $medal['available'] ? 'checked' : '';
switch($medal['type']) {
case 0:
$medal['type'] = cplang('medals_adminadd');
break;
case 1:
$medal['type'] = $medal['price'] ? cplang('medals_buy') : cplang('medals_register');
break;
case 2:
$medal['type'] = cplang('modals_moderate');
break;
}
showtablerow('', array('class="td25"', 'class="td25"', 'class="td25"', '', '', '', 'class="td23"', 'class="td25"'), array(
"",
"",
"",
"",
"",
"",
$medal[type],
"$lang[detail]"
));
}
echo '
| |
';
showsubmit('medalsubmit', 'submit', 'del');
showtablefooter();
showformfooter();
} else {
if(is_array($_GET['delete']) && $_GET['delete']) {
$ids = array();
foreach($_GET['delete'] as $id) {
$ids[] = $id;
}
C::t('forum_medal')->delete($_GET['delete']);
}
if(is_array($_GET['name'])) {
foreach($_GET['name'] as $id => $val) {
$update = array(
'available' => $_GET['available'][$id],
'displayorder' => intval($_GET['displayorder'][$id])
);
if($_GET['name'][$id]) {
$update['name'] = dhtmlspecialchars($_GET['name'][$id]);
}
if($_GET['description'][$id]) {
$update['description'] = dhtmlspecialchars($_GET['description'][$id]);
}
if($_GET['image'][$id]) {
$update['image'] = dhtmlspecialchars($_GET['image'][$id]);
}
C::t('forum_medal')->update($id, $update);
}
}
if(is_array($_GET['newname'])) {
foreach($_GET['newname'] as $key => $value) {
if($value != '' && $_GET['newimage'][$key] != '') {
$data = array('name' => dhtmlspecialchars($value),
'available' => $_GET['newavailable'][$key],
'image' => $_GET['newimage'][$key],
'displayorder' => intval($_GET['newdisplayorder'][$key]),
'description' => dhtmlspecialchars($_GET['newdescription'][$key]),
);
C::t('forum_medal')->insert($data);
}
}
}
updatecache('setting');
updatecache('medals');
cpmsg('medals_succeed', 'action=medals', 'succeed');
}
} elseif($operation == 'mod') {
if(submitcheck('delmedalsubmit')) {
if (is_array($_GET['delete']) && !empty($_GET['delete'])) {
$ids = array();
foreach($_GET['delete'] as $id) {
$ids[] = $id;
}
C::t('forum_medallog')->update($ids, array('type' => 3));
cpmsg('medals_invalidate_succeed', 'action=medals&operation=mod', 'succeed');
} else {
cpmsg('medals_please_input', 'action=medals&operation=mod', 'error');
}
} elseif(submitcheck('modmedalsubmit')) {
if(is_array($_GET['delete']) && !empty($_GET['delete'])) {
$ids = $comma = '';
foreach($_GET['delete'] as $id) {
$ids .= "$comma'$id'";
$comma = ',';
}
$query = DB::query("SELECT me.id, me.uid, me.medalid, me.dateline, me.expiration, mf.medals
FROM ".DB::table('forum_medallog')." me
LEFT JOIN ".DB::table('common_member_field_forum')." mf USING (uid)
WHERE id IN ($ids)");
loadcache('medals');
while($modmedal = DB::fetch($query)) {
$modmedal['medals'] = empty($medalsnew[$modmedal['uid']]) ? $modmedal['medals'] : $medalsnew[$modmedal['uid']];
foreach($modmedal['medals'] = explode("\t", $modmedal['medals']) as $key => $modmedalid) {
list($medalid, $medalexpiration) = explode("|", $modmedalid);
if(isset($_G['cache']['medals'][$medalid]) && (!$medalexpiration || $medalexpiration > TIMESTAMP)) {
$medalsnew[$modmedal['uid']][$key] = $modmedalid;
}
}
$medalstatus = empty($modmedal['expiration']) ? 0 : 1;
$modmedal['expiration'] = $modmedal['expiration'] ? (TIMESTAMP + $modmedal['expiration'] - $modmedal['dateline']) : '';
$medalsnew[$modmedal['uid']][] = $modmedal['medalid'].(empty($modmedal['expiration']) ? '' : '|'.$modmedal['expiration']);
C::t('forum_medallog')->update($modmedal['id'], array('type' => 1, 'status' => $medalstatus, 'expiration' => $modmedal['expiration']));
C::t('common_member_medal')->insert(array('uid' => $modmedal['uid'], 'medalid' => $modmedal['medalid']), 0, 1);
}
foreach ($medalsnew as $key => $medalnew) {
$medalnew = array_unique($medalnew);
$medalnew = implode("\t", $medalnew);
C::t('common_member_field_forum')->update($key, array('medals' => $medalnew));
}
cpmsg('medals_validate_succeed', 'action=medals&operation=mod', 'succeed');
} else {
cpmsg('medals_please_input', 'action=medals&operation=mod', 'error');
}
} else {
$medals = '';
$medallogs = $medalids = $uids = array();
foreach(C::t('forum_medallog')->fetch_all_by_type(2) as $id => $medal) {
$medal['dateline'] = dgmdate($medal['dateline'], 'Y-m-d H:i');
$medal['expiration'] = empty($medal['expiration']) ? $lang['medals_forever'] : dgmdate($medal['expiration'], 'Y-m-d H:i');
$medalids[$medal['medalid']] = $medal['medalid'];
$uids[$medal['uid']] = $medal['uid'];
$medallogs[$id] = $medal;
}
$medalnames = C::t('forum_medal')->fetch_all($medalids);
$medalusers = C::t('common_member')->fetch_all($uids);
foreach($medallogs as $id => $medal) {
$medals .= showtablerow('', '', array(
"",
"{$medalusers[$medal[uid]][username]}",
$medalnames[$medal['medalid']]['name'],
$medal['dateline'],
$medal['expiration']
), TRUE);
}
shownav('extended', 'nav_medals', 'nav_medals_mod');
showsubmenu('nav_medals', array(
array('admin', 'medals', 0),
array('nav_medals_confer', 'members&operation=confermedal', 0),
array('nav_medals_mod', 'medals&operation=mod', 1)
));
showformheader('medals&operation=mod');
showtableheader('medals_mod');
showtablerow('', '', array(
'',
cplang('medals_user'),
cplang('medals_name'),
cplang('medals_date'),
cplang('medals_expr'),
));
echo $medals;
showsubmit('modmedalsubmit', 'medals_modpass', 'select_all', ' ');
showtablefooter();
showformfooter();
}
} elseif($operation == 'edit') {
$medalid = intval($_GET['medalid']);
if(!submitcheck('medaleditsubmit')) {
$medal = C::t('forum_medal')->fetch($medalid);
$medal['permission'] = dunserialize($medal['permission']);
$medal['usergroupallow'] = $medal['permission']['usergroupallow'];
$medal['usergroups'] = (array)$medal['permission']['usergroups'];
$medal['permission'] = $medal['permission'][0];
$credits = array();
$credits[] = array(0, $lang['default']);
foreach($_G['setting']['extcredits'] as $i => $extcredit) {
$credits[] = array($i, $extcredit['title']);
}
$groupselect = array();
foreach(C::t('common_usergroup')->range_orderby_credit() as $group) {
$groupselect[$group['type']] .= '';
}
$usergroups = '';
shownav('extended', 'nav_medals', 'admin');
showsubmenu('nav_medals', array(
array('admin', 'medals', 1),
array('nav_medals_confer', 'members&operation=confermedal', 0),
array('nav_medals_mod', 'medals&operation=mod', 0)
));
showformheader("medals&operation=edit&medalid=$medalid");
showtableheader(cplang('medals_edit').' - '.$medal['name'], 'nobottom');
showsetting('medals_name1', 'namenew', $medal['name'], 'text');
showsetting('medals_img', '', '', '');
showsetting('medals_type1', array('typenew', array(
array(0, $lang['medals_adminadd'], array('creditdiv' => 'none')),
array(1, $lang['medals_apply_auto'], array('creditdiv' => '')),
array(2, $lang['medals_apply_noauto'], array('creditdiv' => 'none'))
)), $medal['type'], 'mradio');
showtagheader('tbody', 'creditdiv', $medal['type'] == 1, 'sub');
showsetting('medals_credit', array('creditnew', $credits), $medal['credit'], 'select');
showsetting('medals_price', 'pricenew', $medal['price'], 'text');
showtagfooter('tbody');
showsetting('medals_usergroups_allow', 'usergroupallow', $medal['usergroupallow'], 'radio', 0, 1);
showsetting('medals_usergroups', '', '', $usergroups);
showtagfooter('tbody');
showsetting('medals_expr1', 'expirationnew', $medal['expiration'], 'text');
showsetting('medals_memo', 'descriptionnew', $medal['description'], 'text');
showtablefooter();
showtableheader('medals_perm', 'notop');
$formulareplace .= '\''.$lang['setting_credits_formula_digestposts'].'\',\''.$lang['setting_credits_formula_posts'].'\',\''.$lang['setting_credits_formula_oltime'].'\',\''.$lang['setting_credits_formula_pageviews'].'\'';
?>
|
$_GET['typenew'],
'description' => dhtmlspecialchars($_GET['descriptionnew']),
'expiration' => intval($_GET['expirationnew']),
'permission' => $formulapermnew,
'image' => $_GET['imagenew'],
'credit' => $_GET['creditnew'],
'price' => $_GET['pricenew'],
);
if($_GET['namenew']) {
$update['name'] = dhtmlspecialchars($_GET['namenew']);
}
C::t('forum_medal')->update($medalid, $update);
updatecache('medals');
cpmsg('medals_succeed', 'action=medals&do=editmedals', 'succeed');
}
}
?>