Commit d93c63e7 authored by mose's avatar mose

misc update

parent 46734d19
......@@ -5,7 +5,6 @@ require_once ('lib/cc/cclib.php');
if (!isset($_REQUEST['page'])) { $_REQUEST['page'] = ''; }
$page = $_REQUEST['page'];
if (!isset($_SESSION['viewrange'])) { $_SESSION['viewrange'] = 'reg'; }
if (isset($_REQUEST['all'])) {
$_SESSION['viewrange'] = 'all';
} elseif (isset($_REQUEST['local'])) {
......@@ -16,16 +15,6 @@ if (isset($_REQUEST['all'])) {
$_SESSION['viewrange'] = 'reg';
}
if (!isset($_SESSION['localview'])) { $_SESSION['localview'] = 'n'; }
if (isset($_REQUEST['local'])) {
if ($_REQUEST['local'] == 'y') {
$_SESSION['localview'] = 'y';
} else {
$_SESSION['localview'] = 'n';
}
}
$mid = "cc/index.tpl";
$view = '';
......@@ -190,11 +179,7 @@ if ($user) {
$smarty->assign('msg',"Currency ". $_REQUEST['cc_id'] ." created.");
$ccuser = $cclib->user_infos($user);
}
if ($_SESSION['localview'] == 'y') {
$thelist = $cclib->get_currencies(true,0,-1,$sort_mode,'',$owner,'y',false,false,'');
} else {
$thelist = $cclib->get_currencies(true,0,-1,$sort_mode,'',$owner,'y',false,false,'*');
}
$thelist = $cclib->get_currencies(true,0,-1,$sort_mode,'',$owner,'y');
$smarty->assign('thelist', $thelist['data']);
$mid = "cc/currencies.tpl";
$view = 'my';
......@@ -231,17 +216,9 @@ if ($user) {
$view = 'my';
} else {
if ($tiki_p_cc_admin == 'y' and $_SESSION['viewrange'] == 'all') {
if ($_SESSION['localview'] == 'y') {
$thelist = $cclib->get_currencies(true,0,-1,$sort_mode);
} else {
$thelist = $cclib->get_currencies(true,0,-1,$sort_mode,'',false,false,false,'*');
}
$thelist = $cclib->get_currencies(true,0,-1,$sort_mode,'',false,false,false,"%");
} else {
if ($_SESSION['localview'] == 'y') {
$thelist = $cclib->get_currencies(false,0,-1,$sort_mode);
} else {
$thelist = $cclib->get_currencies(false,0,-1,$sort_mode,'',false,false,false,'*');
}
$thelist = $cclib->get_currencies(false,0,-1,$sort_mode);
}
$view = '';
}
......@@ -251,7 +228,6 @@ if ($user) {
}
}
$smarty->assign('local', $_SESSION['localview']);
$smarty->assign('view', $view);
$smarty->assign('page', $page);
$smarty->assign('mid', $mid);
......
......@@ -14,7 +14,7 @@ class CcLib extends UsersLib {
function CcLib($dbTiki) {
$this->db = $dbTiki;
$this->date = date("U");
$this->logfile = "temp/cc.log.php";
$this->logfile = "mods/features/cc/cc.log.php";
$this->initlog();
}
......@@ -52,7 +52,7 @@ class CcLib extends UsersLib {
$mid[] = "`cc_id`=?";
$bindvars[] = $cc;
}
if ($app) {
if ($approved) {
$mid[] = "`approved`=?";
$bindvars[] = $app;
}
......@@ -110,46 +110,48 @@ class CcLib extends UsersLib {
return $retval;
}
function get_currencies($all=false,$offset=0,$max=-1,$sort_mode='cc_name_asc',$find='',$owner=false,$app=false,$reg=false,$cpun='') {
function get_currencies($all=false,$offset=0,$max=-1,$sort_mode='cc_name_asc',$find='',$owner=false,$app=false,$reg=false) {
$bindvars = $mid = array();
$query = "select cc.* from `cc_cc` as cc left join `cc_ledger` as ccl on ccl.`cc_id`=cc.`id` ";
$query_cant = "select count(*) from `cc_cc` as cc left join `cc_ledger` as ccl on ccl.`cc_id`=cc.`id` ";
if ($reg) {
$mid[] = "ccl.`acct_id`=?";
$query = "select *,count(*) as population from `cc_ledger` as ccl left join `cc_cc` as cc on ccl.`cc_id`=cc.`id` left join `cc_ledger` as cclc on cc.`id`=cclc.`cc_id` ";
$query.= " where ccl.`acct_id`=? group by cclc.`cc_id` order by ";
$query.= $this->convert_sortmode($sort_mode);
$query_cant = "select count(*) from `cc_ledger` as ccl where ccl.`acct_id`=?";
$bindvars[] = $reg;
}
if ($cpun != '*') {
$mid[] = "cc.`cpun`=?";
$bindvars[] = $cpun;
}
if ($find) {
$mid[] = "cc.`cc_name`=?";
$bindvars[] = '%'. $find .'%';
}
if ($owner) {
$mid[] = "cc.`owner_id`=?";
$bindvars[] = $owner;
}
if (!$all) {
$mid[] = "cc.`listed`=?";
$bindvars[] = 'y';
}
if ($app) {
$mid[] = "ccl.`approved`=?";
$bindvars[] = 'y';
}
$order = " order by cc.".$this->convert_sortmode($sort_mode);
if (count($mid)) {
$mid = " where ". implode(' and ',$mid);
$result = $this->query($query.$order,$bindvars,$max,$offset);
$cant = $this->getOne($query_cant,$bindvars);
} else {
$mid = '';
$query = 'select cc.*,count(*) as population from `cc_cc` as cc left join `cc_ledger` as ccl on cc.`id`=ccl.`cc_id`';
$query_cant = 'select count(*) from `cc_cc` as cc left join `cc_ledger` as ccl on cc.`id`=ccl.`cc_id`';
if ($find) {
$mid[] = "cc.`cc_name`=?";
$bindvars[] = '%'. $find .'%';
}
if ($owner) {
$mid[] = "cc.`owner_id`=?";
$bindvars[] = $owner;
}
if (!$all) {
$mid[] = "cc.`listed`=?";
$bindvars[] = 'y';
}
if ($app) {
$mid[] = "ccl.`approved`=?";
$bindvars[] = 'y';
}
$order = " group by cc_id order by ";
$order.= $this->convert_sortmode($sort_mode);
if (count($mid)) {
$mid = " where ". implode(' and ',$mid);
} else {
$mid = '';
}
$result = $this->query($query.$mid.$order,$bindvars,$max,$offset);
$cant = $this->getOne($query_cant.$mid,$bindvars);
}
$result = $this->query($query.$mid.$order,$bindvars,$max,$offset);
$cant = $this->getOne($query_cant.$mid,$bindvars);
$ret = array();
while ($res = $result->fetchRow()) {
$res['population'] = $this->getOne('select count(*) from `cc_ledger` where `cc_id`=?',array($res['id']));
$ret["{$res['id']}...{$res['cpun']}"] = $res;
$ret["{$res['id']}"] = $res;
}
$retval = array();
$retval['data'] = $ret;
......@@ -161,7 +163,7 @@ class CcLib extends UsersLib {
return $this->getOne('select count(*) from `cc_cc` where `id`=? and `cpun`=?',array($id,$cpun));
}
function replace_currency($owner,$id,$name,$description,$approval='n',$listed='y',$seq=false,$cpun='') {
function replace_currency($owner,$id,$name,$description,$approval='n',$listed='y',$seq='',$cpun='') {
global $user;
if ($seq) {
$query = "update `cc_cc` set `cc_name`=?,`cc_description`=?,`owner_id`=?,`requires_approval`=?,`listed`=?,`cpun`=? where `seq`=?";
......@@ -212,7 +214,7 @@ class CcLib extends UsersLib {
$result = $this->query($query,$bindvars);
$ret = array();
while ($res = $result->fetchRow()) {
$ret["{$res['cc_id']}...{$res['cpun']}"] = $res;
$ret["{$res['cc_id']}"] = $res;
}
return $ret;
}
......@@ -301,41 +303,33 @@ class CcLib extends UsersLib {
}
}
function decsv($str) {
$ar = split('","',substr($str,1,-1));
}
function list_providers($url,$refresh=false) {
global $cc_cpun;
$now = time();
if ($refresh) {
if (!checkdnsrr($url,'A')) {
if (!checkdnsrr($url)) {
$this->msg = sprintf(tra('DNS check failed for %s'),$url);
} else {
$fp = @ fsockopen($url, 80, $errno, $errstr, 30);
if (!$fp) {
$this->msg = sprintf(tra('Request failed for %s'),$url)."<br />".$errstr;
} else {
$req = "GET /ccsp.txt HTTP/1.1\r\nHost: $url\r\nConnection: Close\r\n\r\n";
$req = "GET /ccsp.txt HTTP/1.1\r\rHost: $url\r\nConnection: Close\r\n";
fwrite($fp,$req);
$zyva = false;
while (!feof($fp)) {
$line = trim(fgets($fp,1024));
if ($line == '') {
$zyva = true;
continue;
}
if ($zyva) {
$pr = split(',',$line);
if ($pr[0] != $cc_cpun and count($pr) == 3) {
$pr[3] = $now;
$pr[4] = 'y';
$pr[2] = preg_replace(array('/:/','/\//'),array('@','.'),$pr[2]);
$prov["{$pr[0]}"] = $pr;
}
} else {
$headers[] = $line;
$pr[] = split(',',fgets($fp,1024));
if ($pr[0] != $cc_cpun and count($pr) == 3) {
$pr[3] = time();
$pr[4] = 'y';
$data[2] = preg_replace(array('/:/','/\//'),array('@','.'),$data[2]);
$prov["{$pr[0]}"] = $pr;
}
}
fclose($fp);
$allp = $prov;
$result = $this->query('select `cpun`,`url`,`email`,`lastupdate`,`status` from `cc_providers`',array());
$result = $this->query('select `cpun`,`email`,`url`,`lastupdate`,`status` from `cc_providers`',array());
while ($res = $result->fetchRow()) {
if (isset($prov["{$res['cpun']}"])) {
$dr = $prov["{$res['cpun']}"];
......@@ -348,50 +342,34 @@ class CcLib extends UsersLib {
}
}
foreach ($prov as $proo) {
if (count($proo)) {
$query = "insert into `cc_providers`(`cpun`,`url`,`email`,`lastupdate`,`status`) values (?,?,?,?,?)";
$this->query($query,$proo);
if (count($prov)) {
$query = "insert into `cc_providers`(`cpun`,`email`,`url`,`lastupdate`,`status`) values (?,?,?,?,?)";
$this->query($query,$prov);
}
}
foreach ($allp as $p) {
$zyva = $fp = false;
$headers = array();
$url = $p[1];
if (!checkdnsrr($url,'A')) {
$this->msg = sprintf(tra('DNS check failed for %s'),$url);
} else {
$fp = @ fsockopen($url, 80, $errno, $errstr, 30);
if (!$fp) {
$this->msg = sprintf(tra('Request failed for %s'),$url)."<br />".$errstr;
} else {
$req = "GET /ccsp.php HTTP/1.1\r\nHost: $url\r\nConnection: Close\r\n\r\n";
fwrite($fp,$req);
while (!feof($fp)) {
$line = trim(fgets($fp,1024));
if ($line == '') {
$zyva = true;
continue;
}
if ($zyva) {
$a = split('","',substr($line,1,-1));
if (count($a) == 5) {
$this->replace_currency($a[0],$a[1],$a[2],stripslashes($a[3]),$a[4],'y',false,$p[0]);
}
} else {
$headers[] = $line;
}
}
fclose($fp);
$allp = array();
foreach ($prov as $p) {
$fp = @ fsockopen($p[1], 80, $errno, $errstr, 30);
if ($fp) {
$req = "GET /ccsp.php HTTP/1.1\r\rHost: ".$p[1]."\r\nConnection: Close\r\n";
fwrite($fp,$req);
while (!feof($fp)) {
$a = split('","',substr(fgets($fp,1025),1,-1));
$this->replace_currency($a[0],$a[1],$a[2],stripslashes($a[3]),$a[4],'y',false,$p[0]);
}
fclose($fp);
}
}
}
}
if (count($allp)) {
foreach ($allp as $url=>$data) {
$data[2] = preg_replace(array('/:/','/\//'),array('@','.'),$data[2]);
}
}
}
$result = $this->query('select `cpun`,`email`,`url`,`lastupdate`,`status` from `cc_providers`',array());
$ret = array();
while ($res = $result->fetchRow()) {
$res['cc'] = $this->getOne('select count(*) from `cc_cc` where `cpun`=?',array($res['cpun']));
$ret[] = $res;
}
return $ret;
......
......@@ -12,7 +12,7 @@ if (!is_object($cclib)) {
include "lib/cc/cclib.php";
}
if ($user) {
$myinfo = $cclib->user_infos($user);
$myinfo = $cclib->user_infos($user,'y');
}
$smarty->assign('myinfo', $myinfo['registered_cc']);
$smarty->assign('nonums', isset($module_params["nonums"]) ? $module_params["nonums"] : 'n');
......
......@@ -24,26 +24,10 @@
</table>
</form>
<div class="wikitext">
<h1>{tr}Currencies Providers{/tr}</h1>
<div class="admin">
<span class="button2"><a href="cc-admin.php?providers_refresh=1" class="linkbut">{tr}Refresh{/tr}</a></span>
<span class="button2"><a href="" class="linkbut">{tr}{/tr}</a></span>
<br /><br />
<table>
<tr>
<th>CPUN</th>
<th>url</th>
<th>Last update</th>
<th>Currencies</th>
</tr>
{foreach item=p from=$providers}
<tr>
<td>{$p.cpun}</td>
<td><a href="http://{$p.url}">http://{$p.url}</a></td>
<td>{$p.lastupdate|tiki_short_date}</td>
<td style="text-align:right">{$p.cc}</td>
</tr>
{/foreach}
</table>
{/foreach}
</div>
......@@ -4,13 +4,8 @@
{if $tiki_p_cc_create eq 'y' or $tiki_p_cc_admin eq 'y'}
<span class="button2"><a href="cc.php?page=currencies&amp;new=1" class="linkbut">Create new currency</a></span>
<br /><br />
{/if}
&nbsp;&nbsp;&nbsp;
<span class="button2"><a href="cc.php?page=currencies&amp;local=n" class="linkbut{if $local eq 'n'} highlight{/if}">Global Currencies</a></span>
<span class="button2"><a href="cc.php?page=currencies&amp;local=y" class="linkbut{if $local eq 'y'} highlight{/if}">Local Currencies</a></span>
</div>
<br />
{if $msg}<div class="simplebox">{$msg}</div>{/if}
......@@ -48,10 +43,6 @@ Register an existing unlisted currency
<th align="left"><a class="tableheading" href="cc.php?page=currencies&amp;sort_mode=cc_name_{if $smarty.request.sort_mode eq 'cc_name_desc'}asc{else}desc{/if}{if $userid}&amp;user={$userid}{/if}">{tr}Name{/tr}</a></th>
<th align="left"><a class="tableheading" href="cc.php?page=currencies&amp;sort_mode=cc_description_{if $smarty.request.sort_mode eq 'cc_description_desc'}asc{else}desc{/if}{if $userid}&amp;user={$userid}{/if}">{tr}Description{/tr}</a></th>
<th align="left"><a class="tableheading" href="cc.php?page=currencies&amp;sort_mode=owner_id_{if $smarty.request.sort_mode eq 'owner_id_desc'}asc{else}desc{/if}{if $userid}&amp;user={$userid}{/if}">{tr}Owner{/tr}</a></th>
{if $local eq 'n'}
<th align="left"><a class="tableheading" href="cc.php?page=currencies&amp;sort_mode=cpun_{if $smarty.request.sort_mode eq 'cpun_desc'}asc{else}desc{/if}{if
$userid}&amp;user={$userid}{/if}" title="{tr}Currency Provider Unique Name{/tr}">{tr}CPUN{/tr}</a></th>
{/if}
<th align="center"><a class="tableheading" href="cc.php?page=currencies&amp;sort_mode=requires_approval_{if $smarty.request.sort_mode eq 'requires_approval_desc'}asc{else}desc{/if}{if $userid}&amp;user={$userid}{/if}">{tr}Approval?{/tr}</a></th>
<th align="center"><a class="tableheading" href="cc.php?page=currencies&amp;sort_mode=listed_{if $smarty.request.sort_mode eq 'listed_desc'}asc{else}desc{/if}{if $userid}&amp;user={$userid}{/if}">{tr}Listed?{/tr}</a></th>
<th align="right"><a class="tableheading" href="cc.php?page=currencies&amp;sort_mode=population_{if $smarty.request.sort_mode eq 'population_desc'}asc{else}desc{/if}{if $userid}&amp;user={$userid}{/if}">{tr}Population{/tr}</a></th>
......@@ -79,17 +70,10 @@ style="background-color : #eee;"
<img src="img/cc/currency.png" width="9" height="10" border="0" alt="{tr}Examine{/tr}" />
<b>{$it.cc_name}</b></a></td>
<td>{$it.cc_description}</td>
{if $it.cpun}
<td>{$it.owner_id}</td>
{else}
<td>{$it.owner_id|userlink}</td>
{/if}
{if $local eq 'n'}
<td><b>{$it.cpun|default:"<i style='color:#999;'>$cc_cpun</i>"}</b></td>
{/if}
<td style="text-align:center;">{$it.requires_approval}</td>
<td style="text-align:center;">{$it.listed}</td>
<td style="text-align:center;">{$it.population}</td>
<td align="center">{$it.requires_approval}</td>
<td align="center">{$it.listed}</td>
<td align="center">{$it.population}</td>
<td align="right">
{if $ccuser.registered_cc.$ccid.approved eq 'y'}
<a href="cc.php?page=currencies&amp;unregister={$it.id}" title="{tr}Unregister{/tr}"><img src="img/cc/unregister_c.png" width="20" height="12" border="0" alt="{tr}Unregister{/tr}" /></a>
......@@ -100,7 +84,7 @@ style="background-color : #eee;"
{else}
<a href="cc.php?page=currencies&amp;register={$it.id}" title="{tr}Register{/tr}"><img src="img/cc/register_c.png" width="20" height="12" border="0" alt="{tr}Register{/tr}" /></a>
{/if}
{if !$it.cpun and ($tiki_p_cc_admin eq 'y' or $it.owner_id eq $user)}
{if $tiki_p_cc_admin eq 'y' or $it.owner_id eq $user}
<a href="cc.php?page=currencies&amp;cc_id={$it.id}" title="{tr}Edit{/tr}"><img src="img/cc/edit_c.png" width="20" height="12" border="0" alt="{tr}Edit{/tr}" /></a>
{/if}
......
{* $Header: /cvsroot/tikiwiki/_mods/features/cc/templates/modules/mod-my_ledger.tpl,v 1.1 2005-02-27 10:29:27 mose Exp $ *}
{* $Header: /cvsroot/tikiwiki/_mods/features/cc/templates/modules/mod-my_ledger.tpl,v 1.2 2005-04-13 12:05:27 mose Exp $ *}
{* remove that *}{assign var=feature_cc value='y'}{* end of remove that *}
{if $feature_cc eq 'y' and $user}
{tikimodule title='My ledger' name="user_ledger" flip=$module_params.flip decorations=$module_params.decorations}
<div id="ledgeo"><a href="#" onclick="document.getElementById('ledge').style.display='block';document.getElementById('ledgeo').style.display='none';">{tr}Show{/tr}</a></div>
<div id="ledge" style="display:none;">
<div><a href="#" onclick="document.getElementById('ledge').style.display='none';document.getElementById('ledgeo').style.display='block';">{tr}Hide{/tr}</a></div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Currency</th>
<th>Balance</th>
<th>#</th>
<th>Balance</th>
</tr>
{foreach key=k item=cc from=$myinfo}
<tr>
<td class="module"><a href="cc.php?page=ledgers&cc_id={$k}">{$k}</a></td>
<td class="module" align="right">{$cc.balance}</td>
<td class="module"><a href="cc.php?page=ledgers&cc_id={$k}">{$k|truncate:'16':'...'}</a></td>
<td class="module" align="right">{$cc.tr_count}</td>
<td class="module" style="text-align:right;">{$cc.balance}</td>
</tr>
{/foreach}
</table>
</div>
{/tikimodule}
{/if}
......@@ -42,7 +42,9 @@ $userid}&amp;user={$userid}{/if}{if $ccid}&amp;cc={$ccid}{/if}">{tr}date{/tr}</a
{/if}
<td align="right">{$thelist[i].balance}</td>
<td align="right">
{if $tiki_p_cc_admin eq 'y'}
<a href="" title="{tr}Revert Transaction{/tr}"><img src="img/cc/cancel_transaction.png" width="20" height="12" border="0" alt="{tr}Revert Transaction{/tr}" /></a>
{/if}
</td>
</tr>
{sectionelse}
......
......@@ -53,6 +53,7 @@
</tr><tr>
<td><input type='submit' value='confirm' /></td>
{else}
<input type="hidden" name="tr_type" value="record" />
<td><input name='tr_type' type='submit' value='record' /></td>
{/if}
</tr>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment