Location: PHPKode > projects > CsWebmail > cswebmail-3.10/cswebmail-3.10/templates/labels.php
<?
if(VALID_DOCUMENT != 1) die('what?');
$action = get_var('action');

if($action == 'labels-refresh'){
  $_SESSION['labels'] = new Labels(LABELS_FILE);
  location_header($_SERVER['PHP_SELF'].'?action=labels');
}
else if($action == 'labels-add' || $action == 'labels-save'){
  $_SESSION['labels']->load();
  $_SESSION['labels']->store();
  location_header($_SERVER['PHP_SELF'].'?action=labels');
}
else if($action == 'labels-delete'){
  $_SESSION['labels']->delete(get_var('key'));
  $_SESSION['labels']->store();
  location_header($_SERVER['PHP_SELF'].'?action=labels');
}
else if($action == 'labels-edit'){
  $update = false;
  if(get_var('key') !== null){
    $label = $_SESSION['labels']->find(get_var('key'));
    $update = true;
  }
  else
    $label = array('color'=>'#006633');
  
?>
<script type="text/javascript">
var colors = [
   ["#FFFFFF","#FFCCCC","#FFCC99","#FFFF99","#FFFFCC","#99FF99","#99FFFF","#CCFFFF","#CCCCFF","#FFCCFF"],
   ["#CCCCCC","#FF6666","#FF9966","#FFFF66","#FFFF33","#66FF99","#33FFFF","#66FFFF","#9999FF","#FF99FF"],
   ["#C0C0C0","#FF0000","#FF9900","#FFCC66","#FFFF00","#33FF33","#66CCCC","#33CCFF","#6666CC","#CC66CC"],
   ["#999999","#CC0000","#FF6600","#FFCC33","#FFCC00","#33CC00","#00CCCC","#3366FF","#6633FF","#CC33CC"],
   ["#666666","#990000","#CC6600","#CC9933","#999900","#009900","#339999","#3333FF","#6600CC","#993399"],
   ["#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366"],
   ["#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"],
   ];
function update_color(color,id){
  var e = document.getElementById(id);
  e.style.backgroundColor = color;
}
function setColor(color,id){
  var e = document.getElementById(id);
  e.value = color;
  e.focus();
} 
function togglePalette(e,id){
  var palette = document.getElementById('palette');
  //if current command dialog is currently open, close it
  if (palette.style.visibility == "hidden") {
    var coord = {x:-4,y:17};
    var p = e;
    while(p){
      coord.x += p.offsetLeft;
      coord.y += p.offsetTop;
      p = p.offsetParent;
    }
    palette.style.left = coord.x+"px";
    palette.style.top = coord.y+"px";
    palette.style.visibility = 'visible';
    var c = '<div class="mono">';
    for(var i=0;i<colors.length;i++){
      for(var j=0;j<colors[i].length;j++){
        c += '<span style="background-color:'+colors[i][j]+'" class="hand" title="'+colors[i][j]+'" onclick="setColor(\''+colors[i][j]+'\',\''+id+'\');togglePalette();">&nbsp;&nbsp;</span>';
      }
      c += '<br/>';
    }
    palette.innerHTML = c;
  }
  else{
    palette.style.visibility = 'hidden';
  }
} 
function getOffsetTop(elm) {
  var mOffsetTop = elm.offsetTop;
  var mOffsetParent = elm.offsetParent;

  while(mOffsetParent) {
    mOffsetTop += mOffsetParent.offsetTop;
    mOffsetParent = mOffsetParent.offsetParent;
  }

  return mOffsetTop;
}
function getOffsetLeft(elm) {
  var mOffsetLeft = elm.offsetLeft;
  var mOffsetParent = elm.offsetParent;

  while(mOffsetParent) {
    mOffsetLeft += mOffsetParent.offsetLeft;
    mOffsetParent = mOffsetParent.offsetParent;
  }

  return mOffsetLeft;
}
 
</script>
<div id="palette" style="visibility:hidden;position:absolute;background-color:black;padding:1px;"></div>
   
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" class="block">
<input type="hidden" name="action" value="labels-add"/>
<?if($update){?>
<input type="hidden" name="key" value="<?=htmlspecialchars(get_var('key'))?>"/>
<?}?>
<table class="content hsides">
<tr><th colspan="2" class="title"><?=$update?'Update Label':'Add New Label'?></th></tr>
<tr>
   <td class="bold right">Name : </td>
   <td><input type="text" name="name" class="w100" value="<?=htmlspecialchars($label['name'])?>"/></td>
</tr>
<tr>
   <td class="bold right">Shortcut : </td>
   <td><input type="text" name="shortcut" class="w100" value="<?=htmlspecialchars($label['shortcut'])?>"/></td>
</tr>
<tr>
   <td class="bold right">Color : </td>
   <td>
   <span class="mono" style="background-color:<?=htmlspecialchars($label['color'])?>;margin:4px;" id="color_example">&nbsp;&nbsp;</span>
   <input type="text" name="color" id="color_text" size="8" onblur="update_color(this.value,'color_example')" onfocus="update_color(this.value,'color_example')" value="<?=htmlspecialchars($label['color'])?>"/>
   <a onclick="togglePalette(this,'color_text')">choose color</a>
   </td>
</tr>
   
<tr><td colspan="2">
<input type="submit" value="<?=$update?'update':'add'?>"/>
<input type="submit" value="cancel" onclick="this.form['action'].value='labels'"/>
</td></tr>
</table>
</form>
<? 
}else{?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" name="action"/>
<table class="content hsides">
<tr><th colspan="4" class="title">Labels</th></tr>
<?=$_SESSION['labels']->get_presentation()?>
<tr><td colspan="4">
<input type="submit" value="new" onclick="action.value='labels-edit'"/>
<input type="submit" value="refresh" onclick="action.value='labels-refresh'"/>
<input type="submit" value="delete" onclick="action.value='labels-delete'"/>
</td></tr>
</table>
</form>

<?}?>
Return current item: CsWebmail