Example #1
0
function UserAttributeValueCbGroup($user,$attribute) {
	if (!$user || !$attribute) return;
  global $table_prefix,$tables;
  if ($tables["attribute"]) {
  	$att_table = $tables["attribute"];
    $user_att_table = $tables["user_attribute"];
  } else {
  	$att_table = "attribute";
    $user_att_table = "user_attribute";
  }
  # workaround for integration webbler/phplist
  if (!isset($table_prefix))
  	$table_prefix = "phplist_";

  $att = Sql_Fetch_array_Query("select * from $att_table where id = $attribute");
  $values_req = Sql_Fetch_Row_Query("select value from $user_att_table where userid = $user and attributeid = $attribute");
  $values = split(",",$values_req[0]);
  $html = sprintf('<input type="hidden" name="cbgroup[]" value="%d"><table>',$attribute);
 # $html = sprintf('<select name="attribute[%d]" style="attributeinput" >',$attribute);
  $res = Sql_Query("select id,name from $table_prefix"."listattr_".$att["tablename"]." order by listorder,name");
  if (!Sql_Affected_Rows())
  	return "(No values available)";
  while ($row = Sql_Fetch_Row($res))
    $html .= sprintf('<tr><td><input type="checkbox" name="cbgroup%d[]" value="%d" %s></td><td>%s</td></tr>',
    	$attribute,$row[0],in_array($row[0],$values)?"checked":"",$row[1]);
  return $html . '</table>';
}
Example #2
0
function ListAttributes2011($attributes, $attributedata, $htmlchoice = 0, $userid = 0, $emaildoubleentry = 'no')
{
    global $strPreferHTMLEmail, $strPreferTextEmail, $strEmail, $tables, $table_prefix, $strPreferredFormat, $strText, $strHTML;
    if ($userid) {
        $data = array();
        $current = Sql_Fetch_array_Query("select * from {$GLOBALS["tables"]["user"]} where id = {$userid}");
        $datareq = Sql_Query("select * from {$GLOBALS["tables"]["user_attribute"]} where userid = {$userid}");
        while ($row = Sql_Fetch_Array($datareq)) {
            $data[$row["attributeid"]] = $row["value"];
        }
        $email = $current["email"];
        $htmlemail = $current["htmlemail"];
        # override with posted info
        foreach ($current as $key => $val) {
            if (isset($_POST[$key]) && $key != "password") {
                $current[$key] = $val;
            }
        }
    } else {
        if (isset($_REQUEST['email'])) {
            $email = stripslashes($_REQUEST["email"]);
        } else {
            $email = '';
        }
        if (isset($_POST['htmlemail'])) {
            $htmlemail = $_POST["htmlemail"];
        }
        $data = array();
        $current = array();
    }
    $textlinewidth = sprintf('%d', getConfig("textline_width"));
    if (!$textlinewidth) {
        $textlinewidth = 40;
    }
    list($textarearows, $textareacols) = explode(",", getConfig("textarea_dimensions"));
    if (!$textarearows) {
        $textarearows = 10;
    }
    if (!$textareacols) {
        $textareacols = 40;
    }
    $html = '';
    $html .= '<fieldset class="subscriberdetails">';
    $html .= sprintf('<div class="required"><label for="email">%s</label>
    <input type="text" name="email" value="%s" class="input email required" />', $GLOBALS["strEmail"], htmlspecialchars($email));
    if ($emaildoubleentry == 'yes') {
        if (!isset($_REQUEST['emailconfirm'])) {
            $_REQUEST['emailconfirm'] = '';
        }
        $html .= sprintf('<label for="emailconfirm">%s</label>
      <input type="text" name="emailconfirm" value="%s" class="input emailconfirm required" />', $GLOBALS["strConfirmEmail"], htmlspecialchars(stripslashes($_REQUEST["emailconfirm"])), $GLOBALS["strConfirmEmail"]);
    }
    if (ASKFORPASSWORD) {
        # we only require a password if there isnt one, so they can set it
        # otherwise they can keep the existing, if they do not enter anything
        if (!isset($current['password']) || !$current["password"]) {
            $pwdclass = "required";
            #  $html .= '<input type="hidden" name="passwordreq" value="1" />';
        } else {
            $pwdclass = 'attributename';
            #  $html .= '<input type="hidden" name="passwordreq" value="0" />';
        }
        $html .= sprintf('
      <label for="password">%s</label><input type="password" name="password" value="" class="input password required" />', $GLOBALS["strPassword"]);
        $html .= sprintf('
      <label for="password_check">%s</label><input type="password" name="password_check" value="" class="input password required" />', $GLOBALS["strPassword2"]);
    }
    $html .= '</div>';
    ## class=required
    $htmlchoice = 'checkforhtml';
    ## Write attribute fields
    switch ($htmlchoice) {
        case "textonly":
            if (!isset($htmlemail)) {
                $htmlemail = 0;
            }
            $html .= sprintf('<input type="hidden" name="htmlemail" value="0" />');
            break;
        case "htmlonly":
            if (!isset($htmlemail)) {
                $htmlemail = 1;
            }
            $html .= sprintf('<input type="hidden" name="htmlemail" value="1" />');
            break;
        case "checkfortext":
            if (!isset($htmlemail)) {
                $htmlemail = 0;
            }
            $html .= sprintf('<fieldset class="htmlchoice"><div><input type="checkbox" name="textemail" value="1" %s /><label for="textemail">%s</label></div></fieldset>', empty($htmlemail) ? 'checked="checked"' : '', $GLOBALS["strPreferTextEmail"]);
            break;
        case "radiotext":
            if (!isset($htmlemail)) {
                $htmlemail = 0;
            }
        case "radiohtml":
            if (!isset($htmlemail)) {
                $htmlemail = 1;
            }
            $html .= sprintf('<fieldset class="htmlchoice">
        <legend>%s</legend>
        <div><input type="radio" id="choicetext" name="htmlemail" value="0" %s /><label for="choicetext" class="htmlchoice">%s</label></div>
        <div><input type="radio" id="choicehtml" name="htmlemail" value="1" %s /><label for="choicehtml" class="htmlchoice">%s</label></div>
        </fieldset>', $GLOBALS["strPreferredFormat"], empty($htmlemail) ? 'checked="checked"' : '', $GLOBALS["strText"], !empty($htmlemail) ? 'checked="checked"' : '', $GLOBALS["strHTML"]);
            break;
        case "checkforhtml":
        default:
            if (!isset($htmlemail)) {
                $htmlemail = 0;
            }
            $html .= sprintf('<fieldset class="htmlchoice"><div><input type="checkbox" name="htmlemail" value="1" %s />
        <label for="htmlemail">%s</label></div></fieldset>', !empty($htmlemail) ? 'checked="checked"' : '', $GLOBALS["strPreferHTMLEmail"]);
            break;
    }
    $html .= "</fieldset>\n";
    $html .= '<fieldset class="attributes">' . "\n";
    $attids = join(',', array_keys($attributes));
    $output = array();
    if ($attids) {
        $res = Sql_Query("select * from {$GLOBALS["tables"]["attribute"]} where id in ({$attids})");
        while ($attr = Sql_Fetch_Array($res)) {
            $output[$attr["id"]] = '';
            if (!isset($data[$attr['id']])) {
                $data[$attr['id']] = '';
            }
            $attr["required"] = $attributedata[$attr["id"]]["required"];
            $attr["default_value"] = $attributedata[$attr["id"]]["default_value"];
            $fieldname = "attribute" . $attr["id"];
            #  print "<tr><td>".$attr["id"]."</td></tr>";
            if ($userid && !isset($_POST[$fieldname])) {
                # post values take precedence
                $val = Sql_Fetch_Row_Query(sprintf('select value from %s where
          attributeid = %d and userid = %d', $GLOBALS["tables"]["user_attribute"], $attr["id"], $userid));
                $_POST[$fieldname] = $val[0];
            } elseif (!isset($_POST[$fieldname])) {
                $_POST[$fieldname] = 0;
            }
            switch ($attr["type"]) {
                case "checkbox":
                    $output[$attr["id"]] = '';
                    # what they post takes precedence over the database information
                    if (isset($_POST[$fieldname])) {
                        $checked = !empty($_POST[$fieldname]) ? 'checked="checked"' : '';
                    } else {
                        $checked = !empty($data[$attr["id"]]) ? 'checked="checked"' : '';
                    }
                    $output[$attr["id"]] .= sprintf("\n" . '<input type="checkbox" name="%s" value="on" %s class="input%s" />', $fieldname, $checked, $attr["required"] ? ' required' : '');
                    $output[$attr["id"]] .= sprintf("\n" . '<label for="%s" class="%s">%s</label>', $fieldname, $attr["required"] ? 'required' : '', stripslashes($attr["name"]));
                    break;
                case "radio":
                    $output[$attr["id"]] .= sprintf("\n" . '<fieldset class="radiogroup %s"><legend>%s</legend>', $attr["required"] ? 'required' : '', stripslashes($attr["name"]));
                    $values_request = Sql_Query("select * from {$table_prefix}" . "listattr_" . $attr["tablename"] . " order by listorder,name");
                    while ($value = Sql_Fetch_array($values_request)) {
                        if (!empty($_POST[$fieldname])) {
                            $checked = $_POST[$fieldname] == $value["id"] ? 'checked="checked"' : '';
                        } else {
                            if ($data[$attr["id"]]) {
                                $checked = $data[$attr["id"]] == $value["id"] ? 'checked="checked"' : '';
                            } else {
                                $checked = $attr["default_value"] == $value["name"] ? 'checked="checked"' : '';
                            }
                        }
                        $output[$attr["id"]] .= sprintf('<input type="radio" class="input%s" name="%s" value="%s" %s /><label for="%s">%s</label>', $attr["required"] ? ' required' : '', $fieldname, $value["id"], $checked, $fieldname, $value["name"]);
                    }
                    $output[$attr["id"]] . '</fieldset>';
                    break;
                case "select":
                    $output[$attr["id"]] .= sprintf("\n" . '<fieldset class="selectgroup %s"><label for="%s">%s</label>', $attr["required"] ? 'required' : '', $fieldname, stripslashes($attr["name"]));
                    $values_request = Sql_Query("select * from {$table_prefix}" . "listattr_" . $attr["tablename"] . " order by listorder,name");
                    $output[$attr["id"]] .= sprintf('<select name="%s" class="input%s">', $fieldname, $attr["required"] ? 'required' : '');
                    while ($value = Sql_Fetch_array($values_request)) {
                        if (!empty($_POST[$fieldname])) {
                            $selected = $_POST[$fieldname] == $value["id"] ? 'selected="selected"' : '';
                        } elseif ($data[$attr["id"]]) {
                            $selected = $data[$attr["id"]] == $value["id"] ? 'selected="selected"' : '';
                        } else {
                            $selected = $attr["default_value"] == $value["name"] ? 'selected="selected"' : '';
                        }
                        if (preg_match('/^' . preg_quote(EMPTY_VALUE_PREFIX) . '/i', $value['name'])) {
                            $value['id'] = '';
                        }
                        $output[$attr["id"]] .= sprintf('<option value="%s" %s>%s</option>', $value["id"], $selected, stripslashes($value["name"]));
                    }
                    $output[$attr["id"]] .= "</select>";
                    $output[$attr["id"]] .= "</fieldset>";
                    break;
                case "checkboxgroup":
                    $output[$attr["id"]] .= sprintf("\n" . '<fieldset class="checkboxgroup %s"><label for="%s">%s</label>', $attr["required"] ? 'required' : '', $fieldname, stripslashes($attr["name"]));
                    $values_request = Sql_Query("select * from {$table_prefix}" . "listattr_" . $attr["tablename"] . " order by listorder,name");
                    $cbCounter = 0;
                    while ($value = Sql_Fetch_array($values_request)) {
                        $cbCounter++;
                        $selected = '';
                        if (is_array($_POST[$fieldname])) {
                            $selected = in_array($value["id"], $_POST[$fieldname]) ? 'checked="checked"' : '';
                        } elseif ($data[$attr["id"]]) {
                            $selection = explode(",", $data[$attr["id"]]);
                            $selected = in_array($value["id"], $selection) ? 'checked="checked"' : '';
                        }
                        $output[$attr["id"]] .= sprintf('<input type="checkbox" name="%s[]" id="%s%d" class="input%s" value="%s" %s /><label for="%s%d">%s</label>', $fieldname, $fieldname, $cbCounter, $attr["required"] ? ' required' : '', $value["id"], $selected, $fieldname, $cbCounter, stripslashes($value["name"]));
                    }
                    $output[$attr["id"]] .= '</fieldset>';
                    break;
                case "textline":
                    $output[$attr["id"]] .= sprintf("\n" . '<label for="%s" class="input %s">%s</label>', $fieldname, $attr["required"] ? ' required' : '', $attr["name"]);
                    $output[$attr["id"]] .= sprintf('<input type="text" name="%s" class="input%s" value="%s" />', $fieldname, $attr["required"] ? ' required' : '', isset($_POST[$fieldname]) ? htmlspecialchars(stripslashes($_POST[$fieldname])) : (isset($data[$attr["id"]]) ? $data[$attr["id"]] : $attr["default_value"]));
                    break;
                case "textarea":
                    $output[$attr["id"]] .= sprintf("\n" . '<label for="%s" class="input %s">%s</label>', $fieldname, $attr["required"] ? ' required' : '', $attr["name"]);
                    $output[$attr["id"]] .= sprintf('<textarea name="%s" rows="%d" cols="%d" class="input%s" wrap="virtual">%s</textarea>', $fieldname, $textarearows, $textareacols, $attr["required"] ? ' required' : '', isset($_POST[$fieldname]) ? htmlspecialchars(stripslashes($_POST[$fieldname])) : (isset($data[$attr["id"]]) ? htmlspecialchars(stripslashes($data[$attr["id"]])) : $attr["default_value"]));
                    break;
                case "hidden":
                    $output[$attr["id"]] .= sprintf('<input type="hidden" name="%s" value="%s" />', $fieldname, $data[$attr["id"]] ? $data[$attr["id"]] : $attr["default_value"]);
                    break;
                case "date":
                    require_once dirname(__FILE__) . "/date.php";
                    $date = new Date();
                    $postval = $date->getDate($fieldname);
                    if ($data[$attr["id"]]) {
                        $val = $data[$attr["id"]];
                    } else {
                        $val = $postval;
                    }
                    $output[$attr["id"]] = sprintf("\n" . '<fieldset class="date%s"><label for="%s">%s</label>', $attr["required"] ? ' required' : '', $fieldname, $attr["name"]);
                    $output[$attr["id"]] .= sprintf('%s', $date->showInput($fieldname, "", $val));
                    $output[$attr["id"]] .= '</fieldset>';
                    break;
                default:
                    print "<!-- error: huh, invalid attribute type -->";
            }
            $output[$attr["id"]] .= "\n";
        }
    }
    # make sure the order is correct
    foreach ($attributes as $attribute => $listorder) {
        if (isset($output[$attribute])) {
            $html .= $output[$attribute];
        }
    }
    $html .= '</fieldset>' . "\n";
    ## class=attributes
    #  print htmlspecialchars( '<fieldset class="phplist">'.$html.'</fieldset>');exit;
    return $html;
}
Example #3
0
function ListAttributes($attributes,$attributedata,$htmlchoice = 0,$userid = 0) {
  global $strPreferHTMLEmail,$strPreferTextEmail,
  	$strEmail,$tables,$table_prefix,$strPreferredFormat,$strText,$strHTML;
/*	if (!sizeof($attributes)) {
  	return "No attributes have been defined for this page";
 	}
*/
  if ($userid) {
    $data = array();
    $current = Sql_Fetch_array_Query("select * from {$tables["user"]} where id = $userid");
  	$datareq = Sql_Query("select * from {$tables["user_attribute"]} where userid = $userid");
    while ($row = Sql_Fetch_Array($datareq)) {
      $data[$row["attributeid"]] = $row["value"];
    }

    $email = $current["email"];
    $htmlemail = $current["htmlemail"];
    # override with posted info
    foreach ($current as $key => $val) {
      if ($_POST[$key] && $key != "password") {
        $current[$key] = $val;
      }
    }
  } else {
    $email = stripslashes($_REQUEST["email"]);
    $htmlemail = $_POST["htmlemail"];
  }

  $textlinewidth = sprintf('%d',getConfig("textline_width"));
  if (!$textlinewidth) $textlinewidth = 40;
  list($textarearows,$textareacols) = explode(",",getConfig("textarea_dimensions"));
  if (!$textarearows) $textarearows = 10;
  if (!$textareacols) $textareacols = 40;

  $html = "";
  if ($_GET["page"] != "import1")
  $html .= sprintf('
  <tr><td><div class="required">%s</div></td>
  <td class="attributeinput"><input type=text name=email value="%s" size="%d">
  <script language="Javascript" type="text/javascript">addFieldToCheck("email","%s");</script></td></tr>',
  $strEmail,htmlspecialchars($email),$textlinewidth,$strEmail);

  if ($_GET["page"] != "import1")
  if (ASKFORPASSWORD) {
  	# we only require a password if there isnt one, so they can set it
    # otherwise they can keep the existing, if they do not enter anything
  	if (!$current["password"]) {
    	$pwdclass = "required";
      $js = sprintf('<script language="Javascript" type="text/javascript">addFieldToCheck("password","%s");</script>',$GLOBALS["strPassword"]);
      $js2 = sprintf('<script language="Javascript" type="text/javascript">addFieldToCheck("password_check","%s");</script>',$GLOBALS["strPassword2"]);
      $html .= '<input type=hidden name="passwordreq" value="1">';
    } else {
    	$pwdclass = 'attributename';
      $html .= '<input type=hidden name="passwordreq" value="0">';
    }

  	$html .= sprintf('
  <tr><td><div class="%s">%s</div></td>
  <td class="attributeinput"><input type=password name=password value="" size="%d">%s</td></tr>',
  $pwdclass,$GLOBALS["strPassword"],$textlinewidth,$js);
  	$html .= sprintf('
  <tr><td><div class="%s">%s</div></td>
  <td class="attributeinput"><input type=password name="password_check" value="" size="%d">%s</td></tr>',
  $pwdclass,$GLOBALS["strPassword2"],$textlinewidth,$js2);
 	}

  switch($htmlchoice) {
  	case "textonly":
      $html .= sprintf('<input type=hidden name="htmlemail" value="0">');
      break;
  	case "htmlonly":
      $html .= sprintf('<input type=hidden name="htmlemail" value="1">');
      break;
  	case "checkfortext":
      $html .= sprintf('<tr><td colspan=2>
      <span class="attributeinput">
      <input type=checkbox name="textemail" value="1" %s></span>
      <span class="attributename">%s</span>
      </td></tr>',!$htmlemail,$strPreferTextEmail);
      break;
  	case "radiotext":
    	if (!isset($htmlemail))
      	$htmlemail = 0;
      $html .= sprintf('<tr><td colspan=2>
      	<span class="attributename">%s<br/>
      	<span class="attributeinput"><input type=radio name="htmlemail" value="0" %s></span>
        <span class="attributename">%s</span>
        <span class="attributeinput"><input type=radio name="htmlemail" value="1" %s></span>
        <span class="attributename">%s</span></td></tr>',
        $strPreferredFormat,
        !$htmlemail ? "checked":"",$strText,
        $htmlemail ? "checked":"",$strHTML);
      break;
  	case "radiohtml":
    	if (!isset($htmlemail))
      	$htmlemail = 1;
      $html .= sprintf('<tr><td colspan=2>
      	<span class="attributename">%s</span><br/>
      	<span class="attributeinput"><input type=radio name="htmlemail" value="0" %s></span>
        <span class="attributename">%s</span>
        <span class="attributeinput"><input type=radio name="htmlemail" value="1" %s></span>
        <span class="attributename">%s</span></td></tr>',
        $strPreferredFormat,
        !$htmlemail ? "checked":"",$strText,
        $htmlemail ? "checked":"",$strHTML);
      break;
  	case "checkforhtml":
    default:
      $html .= sprintf('<tr><td colspan=2>
      	<span class="attributeinput"><input type=checkbox name="htmlemail" value="1" %s></span>
        <span class="attributename">%s</span></td></tr>',$htmlemail ? "checked":"",$strPreferHTMLEmail);
      break;
	}
  $html .= "\n";

  $attids = join(',',array_keys($attributes));
  if ($attids) {
    $res = Sql_Query("select * from {$tables["attribute"]} where id in ($attids)");
    while ($attr = Sql_Fetch_Array($res)) {
      $attr["required"] = $attributedata[$attr["id"]]["required"];
      $attr["default_value"] = $attributedata[$attr["id"]]["default_value"];
      if ($attr["tablename"] != "")
        $fieldname = $attr["tablename"];
      else
        $fieldname = "attribute" .$attr["id"];
  #  print "<tr><td>".$attr["id"]."</td></tr>";
      if ($userid && !isset($_POST[$fieldname])) {
        # post values take precedence
        $val = Sql_Fetch_Row_Query(sprintf('select value from %s where
          attributeid = %d and userid = %d',$tables["user_attribute"],$attr["id"],$userid));
        $_POST[$postvalue] = $val[0];
      }
      switch ($attr["type"]) {
        case "checkbox":
          $output[$attr["id"]] = '<tr><td colspan=2>';
          # what they post takes precedence over the database information
          if ($_POST[$fieldname])
            $checked = $_POST[$fieldname] ? "checked":"";
          else
            $checked = $data[$attr["id"]] ? "checked":"";
          $output[$attr["id"]] .= sprintf("\n".'<input type="checkbox" name="%s" value="on" %s class="attributeinput">',$fieldname,$checked);
          $output[$attr["id"]] .= sprintf("\n".'<span class="%s">%s</span>',$attr["required"] ? 'required' : 'attributename',stripslashes($attr["name"]));
          break;
        case "radio":
          $output[$attr["id"]] .= sprintf("\n".'<tr><td colspan=2><div class="%s">%s</div>',$attr["required"] ? 'required' : 'attributename',stripslashes($attr["name"]));
          $values_request = Sql_Query("select * from $table_prefix"."listattr_".$attr["tablename"]." order by listorder,name");
          while ($value = Sql_Fetch_array($values_request)) {
            if (isset($_POST[$fieldname]))
              $checked = $_POST[$fieldname] == $value["id"] ? "checked":"";
            else if (isset($data[$attr["id"]]))
              $checked = $data[$attr["id"]] == $value["id"] ? "checked":"";
            else
              $checked = $attr["default_value"] == $value["name"] ? "checked":"";
            $output[$attr["id"]] .= sprintf('&nbsp;%s&nbsp;<input type=radio  class="attributeinput" name="%s" value="%s" %s>',
              $value["name"],$fieldname,$value["id"],$checked);
          }
          break;
        case "select":
          $output[$attr["id"]] .= sprintf("\n".'<tr><td><div class="%s">%s</div>',$attr["required"] ? 'required' : 'attributename',stripslashes($attr["name"]));
          $values_request = Sql_Query("select * from $table_prefix"."listattr_".$attr["tablename"]." order by listorder,name");
          $output[$attr["id"]] .= sprintf('</td><td class="attributeinput"><!--%d--><select name="%s" class="attributeinput">',$data[$attr["id"]],$fieldname);
          while ($value = Sql_Fetch_array($values_request)) {
            if (isset($_POST[$fieldname]))
              $selected = $_POST[$fieldname] == $value["id"] ? "selected" : "";
            else if (isset($data[$attr["id"]]))
              $selected = $data[$attr["id"]] == $value["id"] ? "selected":"";
            else
              $selected = $attr["default_value"] == $value["name"] ? "selected":"";
            $output[$attr["id"]] .= sprintf('<option value="%s" %s>%s',$value["id"],$selected,stripslashes($value["name"]));
          }
          $output[$attr["id"]] .= "</select>";
          break;
        case "checkboxgroup":
          $output[$attr["id"]] .= sprintf("\n".'<tr><td colspan=2><div class="%s">%s</div>',$attr["required"] ? 'required' : 'attributename',stripslashes($attr["name"]));
          $values_request = Sql_Query("select * from $table_prefix"."listattr_".$attr["tablename"]." order by listorder,name");
          $output[$attr["id"]] .= sprintf('</td></tr>');
          while ($value = Sql_Fetch_array($values_request)) {
            if (isset($_POST[$fieldname]))
              $selected = in_array($value["id"],$_POST[$fieldname]) ? "checked" : "";
            else if (isset($data[$attr["id"]])) {
              $selection = explode(",",$data[$attr["id"]]);
              $selected = in_array($value["id"],$selection) ? "checked":"";
            }
            $output[$attr["id"]] .= sprintf('<tr><td colspan=2 class="attributeinput"><input type=checkbox name="%s[]"  class="attributeinput" value="%s" %s> %s</td></tr>',$fieldname,$value["id"],$selected,stripslashes($value["name"]));
          }
          break;
        case "textline":
          $output[$attr["id"]] .= sprintf("\n".'<tr><td><div class="%s">%s</div>',$attr["required"] ? 'required' : 'attributename',$attr["name"]);
          $output[$attr["id"]] .= sprintf ('</td><td class="attributeinput">
            <input type=text name="%s"  class="attributeinput" size="%d" value="%s">',$fieldname,
            $textlinewidth,
            $_POST[$fieldname] ? htmlspecialchars(stripslashes($_POST[$fieldname])) : ($data[$attr["id"]] ? $data[$attr["id"]] : $attr["default_value"]));
          if ($attr["required"])
            $output[$attr["id"]] .= sprintf('<script language="Javascript" type="text/javascript">addFieldToCheck("%s","%s");</script>',$fieldname,$attr["name"]);
          break;
        case "textarea":
          $output[$attr["id"]] .= sprintf("\n".'<tr><td colspan=2>
            <div class="%s">%s</div></td></tr>',$attr["required"] ? 'required' : 'attributename',
            $attr["name"]);
          $output[$attr["id"]] .= sprintf ('<tr><td class="attributeinput" colspan=2>
            <textarea name="%s" rows="%d"  class="attributeinput" cols="%d" wrap="virtual">%s</textarea>',
            $fieldname,$textarearows,$textareacols,
            $_POST[$fieldname] ? htmlspecialchars(stripslashes($_POST[$fieldname])) : ($data[$attr["id"]] ? $data[$attr["id"]] : $attr["default_value"]));
          if ($attr["required"])
            $output[$attr["id"]] .= sprintf('<script language="Javascript" type="text/javascript">addFieldToCheck("%s","%s");</script>',$fieldname,$attr["name"]);
          break;
        case "hidden":
          $output[$attr["id"]] .= sprintf('<input type=hidden name="%s" size=40 value="%s">',$fieldname,$data[$attr["id"]] ? $data[$attr["id"]] : $attr["default_value"]);
          break;
        default:
          print "<!-- error: huh, invalid attribute type -->";
      }
      $output[$attr["id"]] .= "</td></tr>\n";
    }
  }

  # make sure the order is correct
	foreach ($attributes as $attribute => $listorder) {
  	$html .= $output[$attribute];
 	}
  return $html;
}
Example #4
0
function UserAttributeValueCbGroup($user = 0, $attribute = 0)
{
    #  if (!$user || !$attribute) return;
    global $table_prefix, $tables;
    if ($tables['attribute']) {
        $att_table = $tables['attribute'];
        $user_att_table = $tables['user_attribute'];
    } else {
        $att_table = 'attribute';
        $user_att_table = 'user_attribute';
    }
    # workaround for integration webbler/phplist
    if (!isset($table_prefix)) {
        $table_prefix = 'phplist_';
    }
    $att = Sql_Fetch_array_Query("select * from {$att_table} where id = {$attribute}");
    $values_req = Sql_Fetch_Row_Query("select value from {$user_att_table} where userid = {$user} and attributeid = {$attribute}");
    $values = explode(',', $values_req[0]);
    $html = sprintf('<input type="hidden" name="cbgroup[]" value="%d" /><table>', $attribute);
    # $html = sprintf('<select name="attribute[%d]" style="attributeinput" >',$attribute);
    $res = Sql_Query("select id,name from {$table_prefix}" . 'listattr_' . $att['tablename'] . ' order by listorder,name');
    if (!Sql_Affected_Rows()) {
        return '(No values available)';
    }
    while ($row = Sql_Fetch_Row($res)) {
        $html .= sprintf('<tr><td><input type="checkbox" name="cbgroup%d[]" value="%d" %s /></td><td>%s</td></tr>', $attribute, $row[0], in_array($row[0], $values) ? 'checked' : '', $row[1]);
    }
    return $html . '</table>';
}