Beispiel #1
42
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;
}
Beispiel #2
0
function getUniqid($table = "") {
  global $tables;
  if (!$table) {
  	if ($tables["user"])
	  	$table = $tables["user"];
    else
    	$table = "user";
  }
  # make sure it is really unique
  $id = md5(uniqid(mt_rand()));
  $req = Sql_Query("select id from $table where uniqid = \"$id\"");
  while (Sql_Affected_rows()) {
    $id = md5(uniqid(mt_rand()));
    $req = Sql_Query("select id from $table where uniqid = \"$id\"");
  }
  return $id;
}
Beispiel #3
0
    reset($_SESSION['export']['cols']);
    while (list($key, $val) = each($_SESSION['export']['cols'])) {
        fwrite($exportfile, strtr($user[$val], $col_delim, ',') . $col_delim);
    }
    reset($attributes);
    while (list($key, $val) = each($attributes)) {
        $value = UserAttributeValue($user['id'], $val['id']);
        fwrite($exportfile, quoteEnclosed($value, $col_delim, $row_delim) . $col_delim);
    }
    if ($exporthistory) {
        fwrite($exportfile, quoteEnclosed($user['ip'], $col_delim, $row_delim) . $col_delim);
        fwrite($exportfile, quoteEnclosed($user['summary'], $col_delim, $row_delim) . $col_delim);
        fwrite($exportfile, quoteEnclosed($user['detail'], $col_delim, $row_delim) . $col_delim);
    }
    $lists = Sql_query("select listid,name from\n    {$tables['listuser']},{$tables['list']} where userid = " . $user['id'] . " and\n    {$tables['listuser']}.listid = {$tables['list']}.id {$listselect_and}");
    if (!Sql_Affected_rows($lists)) {
        fwrite($exportfile, 'No Lists');
    }
    while ($list = Sql_fetch_array($lists)) {
        fwrite($exportfile, stripslashes($list['name']) . '; ');
    }
    fwrite($exportfile, $row_delim);
}
print '<script type="text/javascript">
var parentJQuery = window.parent.jQuery;
parentJQuery("#progressbar").updateProgress("' . $todo . ',' . $todo . '");
parentJQuery("#busyimage").hide();
parentJQuery("#progresscount").html("' . s('All done') . '");
</script>';
flush();
$_SESSION['export']['fileready'] = $exportfileName;
 }
 flush();
 keepLock($send_process_id);
 $status = Sql_query('update ' . $tables["message"] . ' set status = "inprocess" where id = ' . $messageid);
 $sendstart = Sql_query('update ' . $tables["message"] . ' set sendstart = now() where sendstart is NULL and id = ' . $messageid);
 output($GLOBALS['I18N']->get('Looking for users'));
 if (Sql_Has_Error($database_connection)) {
     ProcessError(Sql_Error($database_connection));
 }
 # make selection on attribute, users who at least apply to the attributes
 # lots of ppl seem to use it as a normal mailinglist system, and do not use attributes.
 # Check this and take anyone in that case.
 $numattr = Sql_Fetch_Row_Query("select count(*) from " . $tables["attribute"]);
 if ($userselection && $numattr[0]) {
     $res = Sql_query($userselection);
     $num_users = Sql_Affected_rows($res);
     output($num_users . ' ' . $GLOBALS['I18N']->get('users apply for attributes, now checking lists'));
     $user_list = "";
     while ($row = Sql_Fetch_row($res)) {
         $user_list .= $row[0] . ",";
     }
     $user_list = substr($user_list, 0, -1);
     if ($user_list) {
         $user_attribute_query = " and listuser.userid in ({$user_list})";
     } else {
         output($GLOBALS['I18N']->get('No users apply for attributes'));
         $status = Sql_query("update {$tables["message"]} set status = \"sent\",sent = now() where id = \"{$messageid}\"");
         finish("info", "Message {$messageid}: \nNo users apply for attributes, ie nothing to do");
         $script_stage = 6;
         # we should actually continue with the next message
         return;
Beispiel #5
0
             $msg = $cnt . ' ' . $GLOBALS['I18N']->get("users were deleted from this list");
             break;
         default:
             # do nothing
             break;
     }
 }
 if ($_POST["tagaction_all"] != "nothing") {
     $req = Sql_Query(sprintf('select userid from %s where listid = %d', $tables["listuser"], $id));
     switch ($_POST["tagaction_all"]) {
         case "move":
             $cnt = 0;
             while ($user = Sql_Fetch_Row($req)) {
                 Sql_query("delete from {$tables["listuser"]} where listid = {$id} and userid =\n            {$user['0']}");
                 Sql_query("replace into {$tables["listuser"]} (listid,userid)\n            values({$_POST["movedestination_all"]},{$user['0']})");
                 if (Sql_Affected_rows() == 1) {
                     # 2 means they were already on the list
                     $cnt++;
                 }
             }
             $msg = $cnt . ' ' . $GLOBALS['I18N']->get("users were moved to") . ' ' . listName($_POST["movedestination_all"]);
             break;
         case "copy":
             $cnt = 0;
             while ($user = Sql_Fetch_Row($req)) {
                 Sql_query("replace into {$tables["listuser"]} (listid,userid)\n            values({$_POST["copydestination_all"]},{$user['0']})");
                 $cnt++;
             }
             $msg = $cnt . ' ' . $GLOBALS['I18N']->get("users were copied to") . ' ' . listName($_POST["copydestination_all"]);
             break;
         case "delete":
Beispiel #6
0
  }

  flush();
  keepLock($send_process_id);
  $status = Sql_query('update '.$tables["message"].' set status = "inprocess",sendstart = now() where id = '.$messageid);
  output( "Looking for users");
  if (Sql_Has_Error($database_connection)) {  ProcessError(Sql_Error($database_connection)); }

  # make selection on attribute, users who at least apply to the attributes
  # lots of ppl seem to use it as a normal mailinglist system, and do not use attributes.
  # Check this and take anyone in that case.
  $numattr = Sql_Fetch_Row_Query("select count(*) from ".$tables["attribute"]);

  if ($userselection && $numattr[0]) {
    $res = Sql_query($userselection);
    $num = Sql_Affected_rows($res);
    output("$num users apply for attributes, now checking lists");
    $user_list = "";
    while ($row = Sql_Fetch_row($res)) {
      $user_list .= $row[0] . ",";
    }
    $user_list = substr($user_list,0,-1);
    if ($user_list)
      $user_attribute_query = " and ".$tables["listuser"].".userid in ($user_list)";
    else {
      output("No users apply for attributes");
      $status = Sql_query("update {$tables["message"]} set status = \"sent\",sent = now() where id = \"$messageid\"");
      finish("info","Message $messageid: \nNo users apply for attributes, ie nothing to do");
      $script_stage = 6;
      return;
    }
Beispiel #7
0
			default: # do nothing
				break;
		}
	}

	if ($tagaction_all != "nothing") {
		$req = Sql_Query(sprintf('select userid from %s where listid = %d',$tables["listuser"],$id));
		switch ($tagaction_all) {
			case "move":
				$cnt = 0;
				while ($user = Sql_Fetch_Row($req)) {
					Sql_query("delete from {$tables["listuser"]} where listid = $id and userid =
						$user[0]");
					Sql_query("replace into {$tables["listuser"]} (listid,userid)
						values($movedestination_all,$user[0])");
					if (Sql_Affected_rows() == 1) # 2 means they were already on the list
						$cnt++;
				}
				$msg = $cnt . ' users were moved to '.listName($movedestination_all);
				break;
			case "copy":
				$cnt = 0;
				while ($user = Sql_Fetch_Row($req)) {
					Sql_query("replace into {$tables["listuser"]} (listid,userid)
						values($copydestination_all,$user[0])");
					$cnt++;
				}
				$msg = $cnt .' users were copied to '.listName($copydestination_all);
				break;
			case "delete":
				Sql_Query(sprintf('delete from %s where listid = %d',$tables["listuser"],$id));
Beispiel #8
0
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;
}