function fill($prefix, $listid) { global $server_name, $tables, $table_prefix; # check for not too many $domain = getConfig('domain'); $res = Sql_query("select count(*) from {$tables['user']}"); $row = Sql_fetch_row($res); if ($row[0] > 50000) { error('Hmm, I think 50 thousand users is quite enough for a test<br/>This machine does need to do other things you know.'); print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Done. Now there are ' . $row[0] . ' users in the database";</script>' . "\n"; return 0; } # fill the database with "users" who have any combination of attribute values $attributes = array(); $res = Sql_query("select * from {$tables['attribute']} where type = \"select\" or type = \"checkbox\" or type=\"radio\""); $num_attributes = Sql_Affected_rows(); $total_attr = 0; $total_val = 0; while ($row = Sql_fetch_array($res)) { array_push($attributes, $row['id']); ++$total_attr; $values[$row['id']] = array(); $res2 = Sql_query("select * from {$table_prefix}" . 'listattr_' . $row['tablename']); while ($row2 = Sql_fetch_array($res2)) { array_push($values[$row['id']], $row2['id']); ++$total_val; } } $total = $total_attr * $total_val; if (!$total) { Fatal_Error('Can only do stress test when some attributes exist'); return 0; } for ($i = 0; $i < $total; ++$i) { $data = array(); reset($attributes); while (list($key, $val) = each($attributes)) { $data[$val] = current($values[$val]); if (!$data[$val]) { reset($values[$val]); $data[$val] = current($values[$val]); } next($values[$val]); } $query = sprintf('insert into %s (email,entered,confirmed) values("testuser%s",now(),1)', $tables['user'], $prefix . '-' . $i . '@' . $domain); $result = Sql_query($query, 0); $userid = Sql_insert_id(); if ($userid) { $result = Sql_query("replace into {$tables['listuser']} (userid,listid,entered) values({$userid},{$listid},now())"); reset($data); while (list($key, $val) = each($data)) { if ($key && $val) { Sql_query("replace into {$tables['user_attribute']} (attributeid,userid,value) values(" . $key . ",{$userid}," . $val . ')'); } } } } return 1; }
if (isset($user["display"])) { $ls->addColumn($user["email"], " ", $user["display"]); } if (in_array("lists", $columns)) { $lists = Sql_query("SELECT count(*) FROM " . $tables["listuser"] . "," . $tables["list"] . " where userid = " . $user["id"] . " and " . $tables["listuser"] . ".listid = " . $tables["list"] . ".id"); $membership = Sql_fetch_row($lists); $ls->addColumn($user["email"], $GLOBALS['I18N']->get('lists'), $membership[0]); } if (in_array("messages", $columns)) { $msgs = Sql_query("SELECT count(*) FROM " . $tables["usermessage"] . " where userid = " . $user["id"]); $nummsgs = Sql_fetch_row($msgs); $ls->addColumn($user["email"], $GLOBALS['I18N']->get('msgs'), $nummsgs[0]); } if (ENABLE_RSS && in_array("rss", $columns)) { $rss = Sql_query("SELECT count(*) FROM " . $tables["rssitem_user"] . " where userid = " . $user["id"]); $nummsgs = Sql_fetch_row($rss); $ls->addColumn($user["email"], $GLOBALS['I18N']->get('rss'), $nummsgs[0]); if (isset($user["rssfrequency"])) { $ls->addColumn($user["email"], $GLOBALS['I18N']->get('rss freq'), $user["rssfrequency"]); } $last = Sql_Fetch_Row_Query("select last from {$tables["user_rss"]} where userid = " . $user["id"]); if ($last[0]) { $ls->addColumn($user["email"], $GLOBALS['I18N']->get('last sent'), $last[0]); } } if (in_array("bounces", $columns)) { $ls->addColumn($user["email"], $GLOBALS['I18N']->get('bncs'), $user["bouncecount"]); } } } print $ls->display();
ProcessError($GLOBALS['I18N']->get('Message I was working on has disappeared')); } elseif ($status['status'] != 'inprocess') { ProcessError($GLOBALS['I18N']->get('Sending of this message has been suspended')); } flush(); # check whether the user has already received the message $um = Sql_query("select entered from {$tables['usermessage']} where userid = {$userdata['0']} and messageid = {$messageid}"); if (!Sql_Affected_Rows()) { if ($script_stage < 4) { $script_stage = 4; } # we know a user $someusers = 1; $users = Sql_query("select id,email,uniqid,htmlemail,rssfrequency,confirmed,blacklisted from {$tables['user']} where id = {$userid}"); # pick the first one (rather historical) $user = Sql_fetch_row($users); if ($user[5] && is_email($user[1])) { $userid = $user[0]; # id of the user $useremail = $user[1]; # email of the user $userhash = $user[2]; # unique string of the user $htmlpref = $user[3]; # preference for HTML emails $rssfrequency = $user[4]; $confirmed = $user[5]; $blacklisted = $user[6]; if (ENABLE_RSS && $processrss) { if ($rssfrequency == $message["rsstemplate"]) { # output("User matches message frequency");
function fill($prefix,$listid) { global $server_name,$tables,$table_prefix; # check for not too many $domain = getConfig("domain"); $res = Sql_query("select count(*) from $tables[user]"); $row = Sql_fetch_row($res); if ($row[0] > 50000) { error("Hmm, I think 50 thousand users is quite enough for a test<br>This machine does need to do other things you know."); print '<script language="Javascript" type="text/javascript">finish();</script>'; print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Done. Now there are '.$row[0].' users in the database";</script>'."\n"; return 0; } # fill the database with "users" who have any combination of attribute values $attributes = array(); $res = Sql_query("select * from $tables[attribute] where type = \"select\" or type = \"checkbox\" or type=\"radio\""); $num_attributes = Sql_Affected_rows(); $total_attr = 0; $total_val = 0; while ($row = Sql_fetch_array($res)) { array_push($attributes,$row["id"]); $total_attr++; $values[$row["id"]] = array(); $res2 = Sql_query("select * from $table_prefix"."listattr_".$row["tablename"]); while ($row2 = Sql_fetch_array($res2)) { array_push($values[$row["id"]],$row2["id"]); $total_val++; } } $total = $total_attr * $total_val; if (!$total) { print '<script language="Javascript" type="text/javascript"> finish(); </script>'; Fatal_Error("Can only do stress test when some attributes exist"); return 0; } for ($i = 0;$i< $total;$i++) { $data = array(); reset($attributes); while (list($key,$val) = each ($attributes)) { $data[$val] = pos($values[$val]); if (!$data[$val]) { reset($values[$val]); $data[$val] = pos($values[$val]); } next($values[$val]); } $query = sprintf('insert into %s (email,entered,confirmed) values("testuser%s",now(),1)', $tables["user"], $prefix . '-' . $i . '@' . $domain); $result = Sql_query($query,0); $userid = Sql_insert_id(); if ($userid) { $result = Sql_query("replace into $tables[listuser] (userid,listid,entered) values($userid,$listid,now())"); reset($data); while (list($key,$val) = each ($data)) if ($key && $val) Sql_query("replace into $tables[user_attribute] (attributeid,userid,value) values(".$key.",$userid,".$val.")"); } } return 1; }
} /* if (isset ($user['foreignkey'])) { $ls->addColumn($user["email"], $GLOBALS['I18N']->get('key'), $user["foreignkey"]); } if (isset ($user["display"])) { $ls->addColumn($user["email"], " ", $user["display"]); } */ if (in_array('lists', $columns)) { $lists = Sql_query('SELECT count(*) FROM ' . $tables['listuser'] . ',' . $tables['list'] . ' where userid = ' . $user['id'] . ' and ' . $tables['listuser'] . '.listid = ' . $tables['list'] . '.id'); $membership = Sql_fetch_row($lists); $ls->addColumn($user['email'], $GLOBALS['I18N']->get('lists'), $membership[0]); } if (in_array('messages', $columns)) { $msgs = Sql_query('SELECT count(*) FROM ' . $tables['usermessage'] . ' where userid = ' . $user['id'] . ' and status = "sent"'); $nummsgs = Sql_fetch_row($msgs); $ls_msgs = $GLOBALS['I18N']->get('msgs') . ': ' . $nummsgs[0]; } ### allow plugins to add columns if (isset($GLOBALS['plugins']) && is_array($GLOBALS['plugins'])) { foreach ($GLOBALS['plugins'] as $plugin) { if (method_exists($plugin, 'displayUsers')) { $plugin->displayUsers($user, $user['email'], $ls); } } } $ls_bncs = ''; if (in_array('bounces', $columns) && !empty($user['bouncecount'])) { $ls_bncs = $GLOBALS['I18N']->get('bncs') . ': ' . $user['bouncecount']; } $ls->addRow($user['email'], "<div class='listinghdname gray'>" . $ls_msgs . '<br />' . $ls_bncs . '</div>', $ls_del . ' ' . $ls_confirmed);