View Single Post
  #1  
Old 13th February 2013, 21:19
mat22 mat22 is offline
Senior Member
 
Join Date: Jun 2009
Latvia
Posts: 119
Default Promoting to VIP for certain time. Auto demote.
Hello!
So I've been struggling with this whole day and I feel really stupid because I can't get this to work even partly.

So what I tried to do is make a system where I can promote users to VIP for certain time (1 week, 2 weeks etc.) and after the time ends - they get automatically demoted (that part I haven't made yet but that's the easiest part). Problem is - even promoting isn't working. That's so annoying. Haha.
So I thought maybe someone can take a quick look at my code and say what's wrong.

userdetails.php part of code
Code:
// VIP ar termiņu
print("<tr><td class=\"rowhead\"" . (!$warned ? " rowspan=\"2\"": "") . ">VIP uz laiku</td>
<td align=\"left\" width=\"20%\">" .
( $viptime
  ? "<input name=\"viptime\" value=\"yes\" type=\"radio\" checked>".$tracker_lang['yes']."<input name=\"viptime\" value=\"no\" type=\"radio\">".$tracker_lang['no'].""
 	: "".$tracker_lang['no']."" ) ."</td>");

	if ($viptime) {
		$vipuntil = $user['vipuntil'];
		if ($vipuntil == '0000-00-00 00:00:00')
    		print("<td align=\"center\">Uz bezgalīgu termiņu</td></tr>\n");
		else {
    		print("<td align=\"center\">Līdz $vipuntil");
	    	print(" (" . mkprettytime(strtotime($vipuntil) - gmtime()) . " palicis)</td></tr>\n");
 	    }
  } else {
    print("<td>VIP līdz<select name=\"viplength\">\n");
    print("<option value=\"0\">------</option>\n");
    print("<option value=\"1\">1 ".$tracker_lang['week']."</option>\n");
    print("<option value=\"2\">2 ".$tracker_lang['weeks']."</option>\n");
    print("<option value=\"4\">4 ".$tracker_lang['weeks']."</option>\n");
    print("<option value=\"8\">8 ".$tracker_lang['weeks']."</option>\n");
    print("<option value=\"255\">".$tracker_lang['unlimited']."</option>\n");
    print("</select></td></tr>\n");
    print("<tr><td colspan=\"2\" align=\"left\">&nbsp;&nbsp;Komentārs PZ:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"60\" name=\"vippm\"></td></tr>");
  }
// VIP ar termiņu beigas
modtask.php code part
Code:
//VIP time
if ($viptime && $curvip != $viptime) {
    $updateset[] = "viptime = " . sqlesc($viptime);
    $updateset[] = "viptime = '0000-00-00 00:00:00'";
	$updateset[] = "class = ".$arr['oldclass'].;
    $oldclass = $arr['class'];
    if ($viptime == 'no') {
        $modcomment = gmdate("Y-m-d") . " - VIP noņēma - " . $CURUSER['username'] . ".\n". $modcomment;
        $msg = sqlesc("" . $CURUSER['username'] . " - Noņēma tev VIP.");
    }
    
    $added = sqlesc(get_date_time());
    mysql_query("INSERT INTO messages (sender, receiver, msg, added) VALUES (0, $userid, $msg, $added)") or sqlerr(__FILE__, __LINE__);
    
} elseif ($viplength) {
    
    if ($viplength == 255) {
        $modcomment = gmdate("Y-m-d") . " - Tev VIP uzlika " . $CURUSER['username'] . "\nIemesls: $vippm\n" . $modcomment;
        $msg = sqlesc("Jūs tikātpaaugstināts uz VIP no $CURUSER[username]." . ($vippm ? "\nIemesls: $vippm" : ""));
        $updateset[] = "vipuntil = '0000-00-00 00:00:00'";
		mysql_query("UPDATE users SET oldclass=$oldclass AND class = '6'") or sqlerr(__FILE__, __LINE__);
    } else {
        $vipuntil = get_date_time(gmtime() + $viplength * 604800);
        $dur = $viplength . " nedēļ" . ($viplength > 1 ? "ām" : "u");
        $msg = sqlesc("Jūs tikāt paaugstināts par VIP uz $dur no " . $CURUSER['username'] . "." . ($warnpm ? "\nIemesls: $vippm" : ""));
        $modcomment = gmdate("Y-m-d") . " - Paaugstināts par VIP uz $dur no " . $CURUSER['username'] .  "\nIemesls: $vippm\n" . $modcomment;
		mysql_query("UPDATE users SET oldclass=$oldclass AND class = '6'") or sqlerr(__FILE__, __LINE__);
	   $updateset[] = "vipuntil = '$vipuntil'";
    }
    
    $added = sqlesc(get_date_time());
    mysql_query("INSERT INTO messages (sender, receiver, msg, added) VALUES (0, $userid, $msg, $added)") or sqlerr(__FILE__, __LINE__);
    $updateset[] = "viptime = 'yes', vipby=$CURUSER[id], oldclass=$oldclass, class = '6'";
}

// VIP time - end
And database part
Code:
ALTER TABLE  `users` ADD  `viptime` ENUM(  'yes',  'no' ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT  'no',
ADD  `vipuntil` DATETIME NOT NULL ,
ADD  `vipby` VARCHAR( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT  '0000-00-00 00:00:00',
ADD  `oldclass` INT NOT NULL ;
P.S. For database I was to lazy to write everything myself with hand so I used phpmyadmin and added rows to users table that's why there's that "ALTER TABLE" thing.:D

Last edited by mat22; 13th February 2013 at 21:31.
Reply With Quote