'; $fuserID=get_cookie($mycookie); $specialjs=''; #echo '
'.$fuserID; die; $setUID=(isset($_GET['u']))?$_GET['u']:'';$setT=(isset($_GET['t']))?$_GET['t']:''; $fuserID=($setUID)?$setUID:$fuserID; $fuserID=(strlen($fuserID))?$fuserID:0; $userID=0; $pageID=(isset($pageID))?$pageID:0; $giwdirection=0; getinwardlogon(); ### inward login redirects $inwardlogon=($giwdirection==2 && isset($goafterlogin))?$goafterlogin:''; $inwardlogon=($giwdirection==1 && isset($goafterregister))?$goafterregister:$inwardlogon; if($inwardlogon){ $nloc=$inwardlogon.((preg_match("/\?/",$inwardlogon))?'&':'?').'t='.$setT.'&u='.$fuserID; print "\n\nLogon\n\n \n \n"; close_conn($db);exit;} ################ if(preg_match("/^[0-9]+\_[0-9]+$/",$fuserID,$g)){$a=split("_",$fuserID); $userID=$a[0];} #echo "$userID cc $fuserID $now
"; ### check database to see if this is a valid log return if($setUID && $setT && $userID && $db){ $crit="userID = $userID AND dateUpdated = $setT"; $ret=get_one($db,'iT_Tusers','userID',$crit); #echo $ret.' '.$crit; die; if(!$ret){$userID=0;}} #$userID=5; # temp correction for local login #$dbLogURL='http://localhost/cgi-bin/RichardPadwick/user.pl'; #$dbLogURL=$loginPageName; $nologforce=(isset($donotforcelogin))?$donotforcelogin:''; if(!($userID || $nologforce)){goLog($dbLogURL.'?or='.goHex(getenv("HTTP_REFERER")));close_conn($db); exit; } $now=time(); $logout=($userID)?'javascript:logMove(\''.$mycookie.'\',\''.$dbLogURL.'?logout='.$userID.'_3'.'\')': $dbLogURL.'?or='.goHex(getenv("HTTP_REFERER")); $logoutText=($userID)?'logout':'login'; $groupID=(isSet($groupID))?$groupID:0; #echo 'gg '.$groupID; #### organisation - iT_Organisations ############################### if(isset($organisationID) && $db){ $crit="organisationID = '$organisationID'"; $fldset="dateUpdated = $now"; $flds='orgKey,userID,organisationID,organisationName,Title,Forename,Surname,eMail,dateCreated,dateUpdated'; $vals="'',0,'$organisationID','','','','','',$now,$now"; $orgKey=get_one($db,'iT_Organisations','orgKey',$crit); if(!$orgKey){ $ret=insert_data($db,'iT_Organisations',$flds,$vals); #echo $ret.'
'; $orgKey=get_one($db,'iT_Organisations','orgKey',$crit);}} #echo "orgKey $orgKey
"; #### owner - iT_Owners ############################### if(isset($ownerID) && $db){ $orgKey=($orgKey)?$orgKey:0; $crit="ownerID = '$ownerID'"; $fldset="dateUpdated = $now"; $flds='ownerKey,userID,orgKey,ownerID,Title,Forename,Surname,eMail,dateCreated,dateUpdated'; $vals="'',0,$orgKey,'$ownerID','','','','',$now,$now"; $ownerKey=get_one($db,'iT_Owners','ownerKey',$crit); if(!$ownerKey){ $ret=insert_data($db,'iT_Owners',$flds,$vals); #echo $ret.'
'; $ownerKey=get_one($db,'iT_Owners','ownerKey',$crit);}} #echo "ownerKey $ownerKey
"; #### tutorial - iT_Tutorials ############################### if(isset($tutorialID) && $db){ $ownerKey=($ownerKey)?$ownerKey:0; $orgKey=($orgKey)?$orgKey:0; $crit="tutorialID = '$tutorialID'"; $fldset="dateUpdated = $now"; $flds='tutorialKey,ownerKey,tutorialID,tutorialName,tutorialURL,dateCreated,dateUpdated'; $vals="'',$ownerKey,'$tutorialID','','',$now,$now"; $tutorialKey=get_one($db,'iT_Tutorials','tutorialKey',$crit); if(!$tutorialKey){ $ret=insert_data($db,'iT_Tutorials',$flds,$vals); # echo "$ret".'
'; $tutorialKey=get_one($db,'iT_Tutorials','tutorialKey',$crit);} $tutorialURL='http://'.getenv("HTTP_HOST").getenv('REQUEST_URI'); $tutorialURL=preg_replace("/[^\/]+$/",'login.php',$tutorialURL); if($tutorialURL){update_data($db,'iT_Tutorials',"tutorialURL = '$tutorialURL'","tutorialKey = $tutorialKey");} } #echo "tutorialKey $tutorialKey
"; #### Page - iT_Pages ############################### if(isset($pageID) && $db){ $tutorialKey=($tutorialKey)?$tutorialKey:0; $pageUploaded=(isset($pageUploaded))?$pageUploaded:date("l dS F Y h:i:s A"); $crit="pageID = $pageID"; $fldset="dateUpdated = $now,groupID = '$groupID'"; $flds='pageKey,tutorialKey,pageID,groupID,pageUploaded,dateCreated,dateUpdated'; $vals="'',$tutorialKey,$pageID,'$groupID','$pageUploaded',$now,$now"; $pageKey=get_one($db,'iT_Pages','pageKey',$crit); if(!$pageKey){ $ret=insert_data($db,'iT_Pages',$flds,$vals); # echo "$ret".'
'; $pageKey=get_one($db,'iT_Pages','pageKey',$crit);}} #echo "pageKey $pageKey
"; ##### user details ################################################# $User_name=$Title=$Forename=$Surname=$Organisation=$Email=$Country=''; $LastResponse='None recorded'; if($userID){ get_user_data($userID); $crit="userID=$userID"; if(isInt($tutorialKey)){$crit.=" AND tutorialKey=$tutorialKey";} $LastResponseEp=get_max($db,'iT_Responses','dateUpdated',$crit); } if($LastResponseEp){$d=getdate($LastResponseEp);$LastResponse=$d["mday"].' '.$d["month"].' '.$d["year"];} #echo "$LastResponse $crit"; ##### end user details ################################################# ############ tutorial ID ########################################## $mylowestsubtutorialID=0; $subtutorialsList=getsubtutorialsList($tutorialKey,$userID); ## here to get min subtutorialID for following functs $subtutorialCookie='ziToolkitTutID'; $subFacts=(isset($_GET['subtutorialID']))?$_GET['subtutorialID']:get_cookie($subtutorialCookie); $mA=split("_",$subFacts); $subtutorialID=(isset($mA[0]))?$mA[0]:''; $subtutorialDate=(isset($mA[1]))?$mA[1]:''; $subtutorialID=($subtutorialID)?$subtutorialID:$mylowestsubtutorialID; $subtutorialID=($subtutorialID)?$subtutorialID:1; $subtutorialDate=($subtutorialDate)?$subtutorialDate:get_one($db,'iT_Responses','subtutorialDate',"userID = $userID AND tutorialKey = $tutorialKey and subtutorialID = $subtutorialID"); $subtutorialDate=($subtutorialDate)?$subtutorialDate:time(); echo ''; #setcookie($subtutorialCookie,$subtutorialID.'_'.$subtutorialDate,(time()+86400)); #echo "\$subtutorialID $subtutorialID $subtutorialDate
"; $subpageID=(isset($_GET['subpageID']))?$_GET['subpageID']:1; ##update database with input values storeInput($pageID,$tutorialKey,$groupID,$userID,$now,$subpageID,$subtutorialID,$subtutorialDate); ### here to get data following inserts $newinsertHREF=newsubpageID($pageID); $insertsList=getinsertsList($pageID,$tutorialKey,$subtutorialID,$userID); $newsubtutorialHREF=newsubtutorialID($tutorialKey); ### refresh following insert if(isset($_POST["Submit"])){$subtutorialsList=getsubtutorialsList($tutorialKey,$userID); } ### get stored responses for this tutorial/page/user $resp=($bypassresponses)?xinputString():getresponses($pageID,$tutorialKey,$groupID,$userID,1,0,'',$subpageID,$subtutorialID); #$resp='Field0101|a~Field0102|b~Field0103|c~Field0104|d~Field0105|e~Field0201|f~Field0202|g%0Ag~Field0203|h~Field0204|i~Field0205|j'; ########################## ########new pageID ########################## function newsubtutorialID($tutorialKey,$pageName='') { Global $userID; $db=oc(); $crit="userID = $userID AND tutorialKey = $tutorialKey"; $n=get_max($db,'iT_Responses','subtutorialID',$crit); $n++; $ret=$pageName."?subtutorialID=$n".'_'.time();close_conn($db); return $ret; } ########################## ########new pageID ########################## function newsubpageID($pageID,$pageName='') { Global $userID,$tutorialKey,$subtutorialID; $db=oc(); $crit="pageID = $pageID AND userID = $userID AND tutorialKey = $tutorialKey AND subtutorialID = $subtutorialID"; $n=get_max($db,'iT_Responses','subpageID',$crit); $n++; $ret=$pageName."?subpageID=$n";close_conn($db); return $ret; } ######################################################################## function makeinsertsList($pageID,$pageName='',$titlefield=''){ Global $tutorialKey,$userID,$subtutorialID; $x=getinsertsList($pageID,$tutorialKey,$subtutorialID,$userID,$pageName,$titlefield);return $x;} ######################################################################## function makesubtutorialsList($tutorialKey,$pageName=''){ Global $userID; $x=gesubtutorialsList($tutorialKey,$userID,$pageName);return $x;} ########################## ######## ########################## ### sets cookie and fills form ###### $specialjs=" var genexpdate = new Date(); var fuserID='".$fuserID."'; var gencookieName='".$mycookie."'; genexpdate.setTime(genexpdate.getTime() + (60 * 60 * 1000)); if(fuserID != 0){gensetCookie(gencookieName,fuserID,genexpdate);} var curvisval=autoSetCookie(gencookieName,'0',genexpdate); var DBinValues='".$resp."'; var logoutLink=\"$logout\"; var logoutText='$logoutText'; "; ## close database close_conn($db); $pageaftersubmit=(isset($pageaftersubmit))?$pageaftersubmit:''; if(isset($_POST['Submit']) && $pageaftersubmit && !$bypassresponses){print "\n";} #while(list($k)=each($DATABASE)){echo "$k $DATABASE[$k]
";} #phpinfo(); ############## function xinputString() { $out=''; if(isset($_POST["Submit"])){reset($_POST); while(list($k,$v)=each($_POST)){ if(strlen($k) > 0){ $out .= goHex($k).'|'.goHex($v).'~';}} } $out=preg_replace("/\~$/",'',$out); return $out;} ############## function ISvalidate($vString=''){ Global $validatemessage; $v=1; if(postval('Submit')){ $vString=preg_replace("/\r\n\t/"," ",$vString); $vString=preg_replace("/\s+/"," ",$vString); $vString=trim($vString); if($vString){$a=split("\~",$vString); for($x=0;$x"; if($n){ $t=1; if($ab && !(getNumber(postval($n))==$ab)){$t=0;} if($isnum && (preg_match("/[^0-9\.\-]/",postval($n)) || preg_match("/.+\-/",postval($n)) || preg_match("/\.[^\.]*\./",postval($n)) || preg_match("/\.$/",postval($n)))){$t=0;} if(preg_match("/^[\-]?[0-9]+$/",$min) && (getNumber(postval($n))<$min)){$t=0;} if(preg_match("/^[\-]?[0-9]+$/",$max) && (getNumber(postval($n))>$max)){$t=0;} $y=getNumber(postval($n)); #echo "y is $y
"; if(isInt($dec)){if($dec==0 && preg_match("/\./",$y)){$t=0;} else if($dec==1 && !preg_match("/\.[0-9]$/",$y)){$t=0;} else if($dec==2 && !preg_match("/\.[0-9][0-9]$/",$y)){$t=0;}} $y=trim(postval($n)); $emailpattern='^([a-zA-Z0-9\.\-\_\&]+)\@([a-zA-Z0-9\.\-\_\&]+)\.([a-zA-Z]{2,4})$'; if($em && !preg_match("/$emailpattern/",$y)){$t=0;} if(!strlen(postval($n))){$t=($req)?0:1;} if(!$t){$v=0;$validatemessage.=$m.'
';} }} # end for($x=0;$x function goHere(nLoc){\nself.location.replace(nLoc);\n}\ngoHere('$n');\n\n";exit;}} ############## function textCompile($groupID,$pageID=''){ Global $userID,$tutorialKey,$subtutorialID,$subpageID; #### add dummy questions so we have record of all q's when admin submits $result=''; $db=oc(); #### get dataset $byPage=($pageID)?1:0; $byGroup=($groupID)?1:0; $sortBy='questionID ASC'; #echo "$pageID,$tutorialKey,$groupID,$userID,$byPage,$byGroup,$sortBy
"; $mystring=getresponses($pageID,$tutorialKey,$groupID,$userID,$byPage,$byGroup,$sortBy,$subpageID,$subtutorialID); #echo $mystring.'

'; $qArray=split('~',$mystring); $myVals=(array) null; $mySort=(array) null; # echo count($qArray).'
'; count is actual no of cells in array if(strlen($mystring)){ while(list($k)=each($qArray)){ $rArray=split('\|',$qArray[$k]); $r=stripslashes(rawurldecode($rArray[1])); $vArray=split('\|',$r); if(count($vArray)<2){ $a=$rArray[0]; $a=preg_replace("/^[a-zA-Z]+/",'',$a); while(strlen($a)<12){$a="$a".'0';} $a=$a.'f'; $myVals[$a]=$r; $mySort[count($mySort)]=$a; #echo "$a $r".'
'; }}} echo '

'; $sortBy='prepostID ASC'; $mystring=getprepost($pageID,$tutorialKey,$groupID,$byPage,$byGroup,$sortBy); #echo $mystring.'

'; if(strlen($mystring)){ $qArray=split('~',$mystring); # echo count($qArray).'
'; count is actual no of cells in array while(list($k)=each($qArray)){ $rArray=split('\|',$qArray[$k]); $r=stripslashes (rawurldecode($rArray[1])); $vArray=split('\|',$r); if(count($vArray)<2){ $a=$rArray[0]; if(preg_match("/^title/i",$a)){$f='a';}elseif(preg_match("/^intro/i",$a)){$f='b';} elseif(preg_match("/^section/i",$a)){$f='c';}elseif(preg_match("/^clause/i",$a)){$f='d';} elseif(preg_match("/^pre/i",$a)){$f='e';}elseif(preg_match("/^post/i",$a)){$f='g';} $a=preg_replace("/^[a-zA-Z]+/",'',$a); while(strlen($a)<12){$a="$a".'0';} $a=$a.$f; $myVals[$a]=$r; $mySort[count($mySort)]=$a; #echo "$a $r".'
'; }}} sort($mySort); $startdiv=0;$enddiv=0; $lastwasresponse=0; $isresponse=0; while(list($k)=each($mySort)){$ky=$mySort[$k]; $x=(isset($myVals[$ky]))?$myVals[$ky]:''; #$x=(strlen($x))?$x:'Response required!'; #echo "$k bb $ky bb $x
"; $td='';$class=''; $h=''; $h_out=''; if(preg_match("/a$/",$ky)){$td='div'; $class='ftitle'; $h='h1';$h_out='';} elseif(preg_match("/b$/i",$ky)){$td='div'; $class='finfo'; $h='p';$h_out='';} elseif(preg_match("/c$/i",$ky)){$td='div'; $class='fsection'; $h_out='h3';} elseif(preg_match("/d$/i",$ky)){$td='div'; $class='fclause'; $h_out='h4';} elseif(preg_match("/e$/i",$ky)){$td='span'; $class='fpre'; $h='';$h_out='';} elseif(preg_match("/f$/i",$ky) && preg_match("/^Response required\!$/i",$x)){$td='span'; $class='unanswered'; $h='';$h_out='';} elseif(preg_match("/f$/i",$ky)){$td='span'; $class='fresponse'; $h='';$h_out='';} elseif(preg_match("/g$/i",$ky)){$td='span'; $class='fpost'; $h='';$h_out='';} #echo "$ky c $class td $td
"; $h1=($h)?"<$h>":''; $h2=($h)?"":''; $h_out1=($h_out)?"<$h_out>":''; $h_out2=($h_out)?"":''; $isinner=(preg_match("/[efg]$/i",$ky))?1:0; $isresponse=(preg_match("/[f]$/i",$ky))?1:0; #$result.= "ii $isinner sd $startdiv
"; ## if(preg_match("/[e]$/i",$ky) && ($startdiv>0)){$startdiv=0; $result.="

\n\n";} if($isresponse && $lastwasresponse && ($startdiv>0)){$startdiv=0; $result.="

\n\n";} ## new div for inners if($isinner && ($startdiv<1)){$startdiv=1; $result.="
\n

\n";} if(($isinner<1) && ($startdiv>0)){$startdiv=0; $result.="

\n
\n";} if($isresponse){$x=preg_replace("/[\r\n]+/",'
',$x); } $result.= "$h_out1<$td class=\"$class\">$h1$x$h2$h_out2\n"; if(($isinner<1) && ($startdiv>0)){$startdiv=0; $result.="

\n\n";} $lastwasresponse=(preg_match("/[f]$/i",$ky))?1:0; } # end while(list($k)=each($mySort)){ close_conn($db); if(($startdiv>0)){$startdiv=0; $result.="

\n\n";} #echo $result; die; return $result;} ############## function QuestionAnalysis( $AnalysisType, $groupID,$pageID,$questionID, $AnalysisField, $ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField, $FilterByField,$FilterByValue, $FilterByField2,$FilterByValue2, $GroupByField, $SortBy1stField,$SortBy1stOrder, $SortBy2ndField,$SortBy2ndOrder, $ExtraValueField='',$FilterByValueTo=''){ Global $userID,$tutorialKey,$subtutorialID,$subpageID; $db=oc(); ### results sorting $SortBy1stOrder=($SortBy1stOrder)?$SortBy1stOrder:'ASC'; $SortBy2ndOrder=($SortBy2ndOrder)?$SortBy2ndOrder:'ASC'; ## sort by element $sortElement1=(preg_match("/^[0-9]+$/",$SortBy1stField))?$SortBy1stField:''; $sortElement2=(preg_match("/^[0-9]+$/",$SortBy2ndField))?$SortBy2ndField:''; $SortBy1stField=($sortElement1)?'':$SortBy1stField; $SortBy2ndField=($sortElement2)?'':$SortBy2ndField; ### database sort $sortBy=($SortBy1stField)?"$SortBy1stField $SortBy1stOrder":''; $sortBy.=($sortBy && $SortBy2ndField)?',':''; $sortBy.=($SortBy2ndField)?"$SortBy2ndField $SortBy2ndOrder":''; #### get dataset $byPage=($pageID)?1:0; $byGroup=($groupID)?1:0; #echo "$pageID,$tutorialKey,$groupID,$userID,$byPage,$byGroup,$sortBy
"; $mystring=getresponses($pageID,$tutorialKey,$groupID,$userID,$byPage,$byGroup,$sortBy,$subpageID,$subtutorialID); #echo $mystring; if(preg_match("/^sum+$/i",$AnalysisType)){ $result=mySum($questionID,$AnalysisField,$ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField, $FilterByField,$FilterByValue,$FilterByField2,$FilterByValue2,$GroupByField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder,$ExtraValueField,$FilterByValueTo,$mystring,0); } # end Sum else if(preg_match("/^count+$/i",$AnalysisType)){ $result=mySum($questionID,$AnalysisField,$ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField, $FilterByField,$FilterByValue,$FilterByField2,$FilterByValue2,$GroupByField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder,$ExtraValueField,$FilterByValueTo,$mystring,1); } # end Count else if(preg_match("/^list+$/i",$AnalysisType)){ $result=myList($questionID,$AnalysisField,$ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField, $FilterByField,$FilterByValue,$FilterByField2,$FilterByValue2,$GroupByField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder,$ExtraValueField,$FilterByValueTo,$mystring); } # end List close_conn($db); return $result;} ######################################################################## function mySum($questionID,$AnalysisField,$ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField, $FilterByField,$FilterByValue,$FilterByField2,$FilterByValue2,$GroupByField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder,$ExtraValueField,$FilterByValueTo,$mystring,$iscount){ $qArray=split('~',$mystring); $rawsum=0; $tally1=(array) null; $tally2=(array) null; $myGroupNums=(array) null; $myGroups=(array) null; $myGroupTags=(array) null; # echo count($qArray).'
'; count is actual no of cells in array while(list($k)=each($qArray)){ $rArray=split('\|',$qArray[$k]); $r=(isset($rArray[1]))?rawurldecode($rArray[1]):''; $vArray=split('\|',$r); if(count($vArray)==4){ ## so has elements for($x=0;$x<4;$x++){$vArray[$x]=trim($vArray[$x]);} ## filter $FilterByValue=trim($FilterByValue); $FilterByValueTo=trim($FilterByValueTo); $FilterByValue2=trim($FilterByValue2); if((isEl($FilterByField) && (preg_match("/^$FilterByValue$/i",$vArray[$FilterByField-1]) || # numeric range between FilterByValue and $FilterByValueTo (isInt($FilterByValue)&& isInt($FilterByValueTo) && isInt($vArray[$FilterByField-1]) && ($vArray[$FilterByField-1]>=$FilterByValue && $vArray[$FilterByField-1]<=$FilterByValueTo ) ) )) || # no value in $FilterByField (!isEl($FilterByField)) ){ if(isEl($FilterByField2) && preg_match("/^$FilterByValue2$/i",$vArray[$FilterByField2-1]) || !isEl($FilterByField2)){ if(isEl($AnalysisField)){ ## $AnalysisField is an element number ## sorting $addplug1=''; $isgrouping='noGroup'; if(isEl($GroupByField)){ if($vArray[$GroupByField-1]){ $isgrouping=$vArray[$GroupByField-1];}} $xtally1=(isset($tally1[$isgrouping]))?$tally1[$isgrouping]:0; if(isEl($sortElement1)){ $addplug1=(isInt($vArray[$sortElement1-1]))?lzero($vArray[$sortElement1-1]+$xtally1):$vArray[$sortElement1-1]; ## correct for count $addplug1=($iscount)?lzero(1+$xtally1):$addplug1; if(isInt($vArray[$sortElement1-1])){$addbit=($iscount)?1:$vArray[$sortElement1-1]; if(isset($tally1[$isgrouping])){$tally1[$isgrouping]+=$addbit;}else{$tally1[$isgrouping]=$addbit;}} } # end if(isEl($sortElement1)){ $sb1=$addplug1; #echo "isgrouping $isgrouping $xtally1 v ".$vArray[$sortElement1-1]."
"; $addplug2=''; $isgrouping='noGroup'; if(isEl($GroupByField)){ if($vArray[$GroupByField-1]){ $isgrouping=$vArray[$GroupByField-1];}} $xtally2=(isset($tally2[$isgrouping]))?$tally2[$isgrouping]:0; if(isEl($sortElement2)){ $addplug2=(isInt($vArray[$sortElement2-1]))?lzero($vArray[$sortElement2-1]+$xtally2):$vArray[$sortElement2-1]; ## correct for count $addplug2=($iscount)?lzero(1+$xtally2):$addplug2; if(isInt($vArray[$sortElement2-1])){$addbit=($iscount)?1:$vArray[$sortElement2-1];if(isset($tally2[$isgrouping])){$tally2[$isgrouping]+=$addbit;}else{$tally2[$isgrouping]=$addbit;}} } # end if(isEl($sortElement2)) $sb2=$addplug2; ## grouping if(isEl($GroupByField)){ if($vArray[$GroupByField-1]){ $l=$vArray[$GroupByField-1]; if(isset($myGroupNums[$l])){ if(isset($myGroups[$myGroupTags[$l]])){$myGroups[$myGroupTags[$l]]=$sb1.'|'.$sb2.'|'.$l;} if(isInt($vArray[$AnalysisField-1])){$myGroupNums[$l]+=($iscount)?1:$vArray[$AnalysisField-1];}} else{$currentgroup=count($myGroups); $myGroups[$currentgroup]=$sb1.'|'.$sb2.'|'.$l; $myGroupTags[$l]=$currentgroup; $myGroupNums[$l]=($iscount)?1:$vArray[$AnalysisField-1];} }} # end if(isEl($GroupByField)){ - if($vArray[$GroupByField-1]){ ### raw sum if(isInt($vArray[$AnalysisField-1])){$rawsum+=($iscount)?1:$vArray[$AnalysisField-1];} } # end if(isEl($AnalysisField)){ }} # end filter conditions } # end if(count($vArray)==4){ } # end while(list($k) $return=$rawsum; if(isEl($GroupByField)){$return=''; ### sorting if(isEl($sortElement1) || isEl($sortElement2)){$sb=(strlen($SortBy1stOrder))?$SortBy1stOrder:$SortBy2ndOrder; #echo $sb; if(preg_match("/DESC/i",$sb)){rsort($myGroups);} else{sort($myGroups);} } for($x=0;$x'; $return.='

'."$s[2]: ".((isset($myGroupNums[$s[2]]))?''.$myGroupNums[$s[2]]:'').'

'; } # end for loop } # end if(isEl($GroupByField)){ # echo count($myGroups); return $return;} ######################################################################## function lzero($i,$n=10){ while(strlen($i)<$n){$i="0$i";} return $i;} ######################################################################## function sortString($ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder,$ExtraValueField,$mystring){ $mySorts=(array) null; $myxSorts=(array) null; $myOuts=(array) null; $qArray=split('~',$mystring); $myFields=(array) null; $xn=1; while(list($k)=each($qArray)){ $nsort=''; $sort1=''; $sort2=''; $dsort=''; ### default sort is numerical entry point $dsort=lzero($xn); $myOuts[$xn]=$qArray[$k]; $rArray=split('\|',$qArray[$k]); if(isset($rArray[1])){ $r=rawurldecode($rArray[1]); $vArray=split('\|',$r); if(count($vArray)==4){ ## so has elements for($x=0;$x<4;$x++){$vArray[$x]=trim($vArray[$x]);} ### top or bottom sort if(strlen(trim($TopOrBottomSet)) && isEl($ScoreValueField)){ $nsort=(isInt($vArray[$ScoreValueField-1]))?lzero($vArray[$ScoreValueField-1]):$vArray[$ScoreValueField-1];} if(isEl($sortElement1)){$sort1=$vArray[$sortElement1-1];} if(isEl($sortElement2)){$sort2=$vArray[$sortElement2-1];} } # end if(count($vArray)==4) $nl="$nsort|$sort1|$sort2|$dsort|$xn"; #echo $nl.'
'; $mySorts[count($mySorts)]=$nl; } # end if(isset($rArray[1])){ $xn++;} # end while(list($k) $mystring=''; if(preg_match("/top/i",$TopOrBottomSet) && isEl($ScoreValueField)){ rsort($mySorts); } elseif(preg_match("/bottom/i",$TopOrBottomSet) && isEl($ScoreValueField)){sort($mySorts);} else if(preg_match("/desc/i",$SortBy1stOrder) && isEl($sortElement1)){ rsort($mySorts); } else if(preg_match("/desc/i",$SortBy2ndOrder) && isEl($sortElement2)){ rsort($mySorts); } ## is $ReturnNoOfItems #if(isInt($ReturnNoOfItems)){ #for($x=0;($x<$ReturnNoOfItems && $x'; #$mySorts=$myxSorts; #echo 'ccc '.count($mySorts).'
'; #} ## end if(isInt($ReturnNoOfItems)){ for($x=0;$x'; $s=split('\|',$mySorts[$x]); $mystring.=$myOuts[$s[4]].'~';} $mystring=preg_replace("/\~$/",'',$mystring); return $mystring;} ######################################################################## function myList($questionID,$AnalysisField,$ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField, $FilterByField,$FilterByValue,$FilterByField2,$FilterByValue2,$GroupByField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder,$ExtraValueField,$FilterByValueTo,$mystring){ $mystring=sortString($ReturnNoOfItems,$TopOrBottomSet,$ScoreValueField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder,$ExtraValueField,$mystring); $qArray=split('~',$mystring); $myFields=(array) null; $myGroups=(array) null; $myGroupVals=(array) null; $havePrinted=(array) null; # echo count($qArray).'
'; count is actual no of cells in array while(list($k)=each($qArray)){ $rArray=split('\|',$qArray[$k]); if(isset($rArray[1])){ $r=rawurldecode($rArray[1]); $vArray=split('\|',$r); if(count($vArray)==4){ ## so has elements for($x=0;$x<4;$x++){$vArray[$x]=trim($vArray[$x]);} ## filter $FilterByValue=trim($FilterByValue); $FilterByValueTo=trim($FilterByValueTo); $FilterByValue2=trim($FilterByValue2); if((isEl($FilterByField) && (preg_match("/^$FilterByValue$/i",$vArray[$FilterByField-1]) || # numeric range between FilterByValue and $FilterByValueTo (isInt($FilterByValue)&& isInt($FilterByValueTo) && isInt($vArray[$FilterByField-1]) && ($vArray[$FilterByField-1]>=$FilterByValue && $vArray[$FilterByField-1]<=$FilterByValueTo ) ) )) || # no value in $FilterByField (!isEl($FilterByField)) ){ if(isEl($FilterByField2) && preg_match("/^$FilterByValue2$/i",$vArray[$FilterByField2-1]) || !isEl($FilterByField2)){ $sb1=(isEl($sortElement1))?$vArray[$sortElement1-1]:''; $sb2=(isEl($sortElement2))?$vArray[$sortElement2-1]:''; if(isEl($AnalysisField)){ ## $AnalysisField is an element number $fval=$sb1.'|'.$sb2.'|'.$vArray[$AnalysisField-1].'|'; if(isEl($ExtraValueField)){$fval.=$vArray[$ExtraValueField-1];} $myFields[count($myFields)]=$fval; ## grouping if(isEl($GroupByField)){ $l=$vArray[$GroupByField-1]; if(isset($myGroupVals[$l])){$myGroupVals[$l].='~'.goHex($fval); } else{$myGroups[count($myGroups)]=$l;$myGroupVals[$l]=goHex($fval); } } ## end if(isEl($GroupByField)){ } # if(isEl($AnalysisField)){ }} # end filter conditions } # end if(count($vArray)==4){ } # end if(isset($rArray[1])){ } # end while(list($k) $return=''; ### simple list ## $limit=(isInt($ReturnNoOfItems) && ($ReturnNoOfItems<=count($myFields)))?$ReturnNoOfItems:count($myFields); #### sorting $xmyFields=(array) null; for($x=0;$x<$limit;$x++){$xmyFields[$x]=$myFields[$x]; }$myFields=$xmyFields; if(isEl($sortElement1) && preg_match("/DESC/i",$SortBy1stOrder)){rsort($myFields);} elseif(isEl($sortElement1) && preg_match("/ASC/i",$SortBy1stOrder)){sort($myFields);} elseif(isEl($sortElement2) && preg_match("/DESC/i",$SortBy2ndOrder)){rsort($myFields);} elseif(isEl($sortElement2) && preg_match("/ASC/i",$SortBy2ndOrder)){sort($myFields);} for($x=0;$x<$limit;$x++){ #echo "xx $x $myFields[$x]
"; $s=split('\|',$myFields[$x]);$label=trim($s[2]);$label=($label)?$label:"[Element $AnalysisField is empty]"; if($label){ # echo 'x '.$x.'
'; $return.='

'.$label; if(isEl($ExtraValueField)){$return.=": ".''.$s[3];} $return.='

';} # end if(trim($s[0])){ } ### end for loop if(isEl($GroupByField)){$return=''; ### sort groups !! if((isEl($sortElement1) && $sortElement1==$GroupByField) || (isEl($sortElement2) && $sortElement2==$GroupByField)){ $sorder=($sortElement1==$GroupByField)?$SortBy1stOrder:$SortBy2ndOrder; if(preg_match("/DESC/i",$sorder)){rsort($myGroups); } else {sort($myGroups);} } ## end if((isEl($sortElement1) && $sortElement1 etc #echo "$GroupByField,$sortElement1,$SortBy1stOrder,$sortElement2,$SortBy2ndOrder
"; for($x=0;$x'; if(isset($myGroupVals[$l])){ $fArray=split('~',$myGroupVals[$l]); $limit=(isInt($ReturnNoOfItems) && ($ReturnNoOfItems<=count($fArray)))?$ReturnNoOfItems:count($fArray); $xfArray=(array) null; for($z=0;$z<$limit;$z++){$xfArray[$z]=rawurldecode($fArray[$z]);}$fArray=$xfArray; #echo "\$sortElement1 $sortElement1 \$SortBy1stOrder $SortBy1stOrder
"; if(isEl($sortElement1) && preg_match("/DESC/i",$SortBy1stOrder)){rsort($fArray);} elseif(isEl($sortElement1) && preg_match("/ASC/i",$SortBy1stOrder)){sort($fArray);} elseif(isEl($sortElement2) && preg_match("/DESC/i",$SortBy2ndOrder)){rsort($fArray);} elseif(isEl($sortElement2) && preg_match("/ASC/i",$SortBy2ndOrder)){sort($fArray);} for($y=0;$y<$limit;$y++){ $k=rawurldecode($fArray[$y]); $s=split('\|',$k); $label=trim($s[2]);$label=($label)?$label:"[Element $AnalysisField is empty]"; if($label){ $return.='

'.$label; if(isEl($ExtraValueField)){$return.=": ".''.$s[3];} $return.='

';} # end if$label{ } # end for loop $y } # end if(isset($myGroupVals[$l])){ } # end if(trim($myGroups[$x])){ } # end for loop $x } # end if(isEl($GroupByField)){ # echo count($myGroups); return $return;} ######################################################################## function getNumber($v){ $v=preg_replace("/[^[0-9]\.\-]/",'',$v); $v=preg_replace("/\.+/",'.',$v); $v=preg_replace("/\-+/",'-',$v); $v=preg_replace("/^([0-9\-]*\.[0-9\-]*)\..*/","$1",$v); $v=preg_replace("/([0-9\-]+)\-.*/","$1",$v); $v=str_replace(',','',$v); if(!preg_match("/[1-9]/",$v)){$v=0;} return $v;} ######################################################################## function IScalculate($c=''){ Global $DATABASE,$_POST,$subtutorialID; $DCAT=array(); $PCAT=array(); $c=preg_replace("/ +/",'',$c); $c=preg_replace("/\[[\'\"]/",'[',$c); $c=preg_replace("/[\'\"]\]/",']',$c); #$c=preg_replace("/\/D\[([^\]]+)\]/","/((isset(\$DATABASE['$1']))?\$DATABASE['$1']:1)",$c); $x=0; while(preg_match("/D\[([^\]]+)\]/",$c,$g)){ $DCAT['ZX'."$x".'XZ']=$g[1]; $c=preg_replace("/D\[([^\]]+)\]/",'ZX'."$x".'XZ',$c,1); $x++;} $x=0; while(preg_match("/P\[([^\]]+)\]/",$c,$g)){ $PCAT['PX'."$x".'XP']=$g[1]; $c=preg_replace("/P\[([^\]]+)\]/",'PX'."$x".'XP',$c,1); $x++;} while(list($k)=each($DCAT)){ $v=(isset($DATABASE[$DCAT[$k]]))?$DATABASE[$DCAT[$k]]:0; $v=getNumber($v); $c=preg_replace("/$k/","$v",$c);} while(list($k)=each($PCAT)){ $v=(isset($_POST[$PCAT[$k]]))?$_POST[$PCAT[$k]]:0; $v=getNumber($v); $c=preg_replace("/$k/","$v",$c);} $c=preg_replace("/\/([\-]*)0([^\.])/","/$1 1$2",$c); $c=preg_replace("/ +/",'',$c); //$c=str_replace(',','',$c); $a='IScalculate input incorrect'; error_reporting(0); eval('$a='.$c.';'); return $a;} ############## function isVal($i){$x=(preg_match("/^[1-9][0-9]*$/",$i))?1:0;return $x;} function isInt($i){$x=(preg_match("/^[0-9]+$/",$i))?1:0;return $x;} function isEl($i){$x=(preg_match("/^[1-4]$/",$i))?1:0;return $x;} ############## function goLog($nLoc){ echo "\n \n\n";} ############## function get_cookie($mycookie) { $cookieval=0; $cookie_array=split(";",getenv("HTTP_COOKIE")); while(list($k,$v)=each($cookie_array)){$arr=split("=",$v); if(trim($arr[0])==$mycookie){$cookieval=trim($arr[1]);}} return $cookieval;} ############## function unHex($in){ ## not complete // Convert the string back to binary echo pack('H*', $hex_string).'
'; return $in;} ################ function goHex($q){ $q=cleanlinebreaks($q); $q=preg_replace("/\n/","",$q); $o=''; for($x=0;$x0-9a-zA-Z]/",$y))?'%'.sprintf("%.X",ord($y)):$y;} $o=preg_replace("/\/","%0A",$o); return $o;} ################ function cleanlinebreaks($in){$in=preg_replace("/\r\n/","\n",$in); $in=preg_replace("/\n\r/","\n",$in); if(!(preg_match("/\n/",$in))){$in=preg_replace("/\r/","\n",$in);}$in=preg_replace("/\r/","",$in); return($in);} echo(''); ########################################################################################## function commas($fig,$pre){$fig=preg_replace("/\,/",'',$fig); $A=preg_split("/\./",$fig); $figx=(isset($A[0]))?$A[0]:''; $ext=(isset($A[1]))?$A[1]:''; $ext=($ext)?"\.$ext":''; $figx=preg_replace("/^([0-9]+)([0-9][0-9][0-9])$/",'$1,$2',$figx); while(preg_match("/^([0-9]+)([0-9]{3})\,(.*?)$/",$figx)){ $figx=preg_replace("/^([0-9]+)([0-9]{3})\,(.*?)$/",'$1,$2,$3',$figx,1);} $figx=($figx.$ext); return $pre.$figx;} ########################################################################################## ?>

Welcome

. . . to The artist's fees toolkit

The artist's fees toolkit takes you step-by-step through a process to calculate your individual daily rate and prepare quotes for freelance work.

You are guided through a series of forms, where you enter your personal income requirements, overheads particular to your practice and the realistic number of days you can work annually. You enter the figures and the toolkit does all the calculations!

Written by financial expert Richard Murphy and published with Arts Council England support, The artist's fees toolkit is part of a body of advocacy, advisory and practical resources from a-n: The Artists Information Company around good practice in valuing and paying artists.

Richard Murphy is a chartered accountant who regularly contributes to debates on taxation and pension issues as a journalist, campaigner and occasional broadcaster.

Conditions of use

Disclaimer

The Artist's fees toolkit can only offer guidance and information of a general nature and not on specific situations. Neither a-n The Artists Information Company nor the authors can accept any legal responsibility to users of The artist's fees toolkit for the contents thereof.

Copyright

© 2004 Text: Richard Murphy , iTool: a-n The Artists Information Company

All rights reserved.

Artists who are current subscribers to a-n may download or print this text for the limited purpose of use in their business or professional practice as artists.

Parts of this text may be reproduced either in accordance with the provisions of the Copyright Designs and Patents Act 1988 (updated) or with written permission of the publishers.

What this pack is about

This pack does not try to solve all the problems an artist can face in pricing their work. Anyone seeking to do that might be a little too ambitious. Instead it concentrates on pricing the services that many artists choose to supply, as opposed to any tangible products they sell. There are two reasons for this:

  • this area appears, if anything, more subjective than pricing a product;
  • for many artists this is a core part of their work, and their ability to make a living depends upon it, but many people do not appreciate that fact and so tend to undervalue the services supplied.

It does not cover the tangible supply of products and it does not cover how to find work.

Background

Artists face a wider range of problems when faced with the challenge of making a living than do most people. These include:

1. Deciding what to do

For example, the artist has to decide between:

  • Making work for sale, with this in turn having a substantial range of alternatives available within it;
  • Providing services such as residencies and workshop leadership, with, again, a whole range of alternatives available.

For most professions the range of options is narrower once a person has been trained, and the option of undertaking some or all of a diverse range of activities much less likely than it is for the artist.

2. Finding someone to buy it

The artist has little choice but to market their own work, even if that only goes so far as engaging an agent for those in the position to do so. In general this task is easier for many other professions because what they provide is wanted as a matter of varying necessity. In contrast, there is a common feeling amongst those not engaged in the arts that they are an optional addition to life. Inevitably this increases the stress of this process for an artist.

3. Setting a price for it

Some aspects of art are indisputably subjective. Any payment that will be made will depend upon the whim of the purchaser in ascribing value to whatever they are presented with. And most purchasers will consider themselves expert in this process, which is quite unlike the situation faced by most professionals who not only are expert in what they do, but are the main experts in the price of it as well, with that price rarely being subject to significant challenge unless some other aspect of the service has failed.

Art as service provider

The artist who supplies services to a client is part of a substantial community within the UK whose existence is, however, little noticed and maybe even less understood. That broader community is made up of skilled people who choose to provide their services, often defined in terms of a definite time input, on a contractual and usually freelance basis.

That this community is misunderstood is obvious from the government's reaction to its existence. Despite all their talk about promoting small business and the enterprise culture the government's reaction to the provider of contract services is probably more accurately assessed by the challenges that the Inland Revenue have made to the tax status of independent contractors by seeking to subject them to PAYE or by imposing the notorious IR35 rules on their companies, so seeking to limit the expenses they can claim.

Freelance status

This note assumes that the artist who is pricing for their work is a freelance contractor, and will be taxed on that basis. This means that PAYE will not be operated on the payments to be made to them. Do note however that this is only true if:

  • the artist is seeking to undertake a trade by equipping themselves with the necessary resources to do so and is incurring costs in this process and is supplying services to a reasonable range of customers / clients;
  • the artist is taking financial risk in supplying the services;
  • the artist is probably supplying more than their labour and might, for example, also be supplying materials, equipment or ancillary tools and facilities to enable the supply of services to take place;
  • the artist is not undertaking a key role, and particularly one of a management nature, inside the organisation that is paying them;
  • in education the service supplied is not teaching, or if it is, it is only an occasional workshop;
  • most importantly (and with some difficulty in many cases) the artist is either allowed to supply someone else to provide the service if they are unable to do so for any reason (even if in practice they never have) or they are allowed to engage people to assist them to do so without the permission of the person making payment to them.

The above list cannot describe all the conditions that are necessary to prove that an artist is a freelance provider of services, and in some cases, such as education, the rules are specific and tight and many artists who might be considered freelance contractors for any other service are considered employees in this case. If you are in doubt as to your status in general or with regard to any specific contract tax advice should be sought.

Pricing

What can be said is that whenever freelance status is agreed there remains a need to agree a rate for a job of work. The basic processes involved in setting that rate are:

  • deciding what you think you should earn;
  • working out over what period you need to earn this;
  • deciding what additional costs you suffer and which have to be paid before there's anything left over for you, such as:
    • costs an employer usually pays, such as national insurance and pension contributions
    • direct costs of doing the work
    • the ongoing costs you incur to work as an artist.

Using the toolkit

The purpose of the toolkit is to:

  • encourage you to decide what your target annual earnings are;
  • assist you in working out what the cost to an employer of paying that rate is;
  • help you work out the number of days a year on which you can really work;
  • calculate your daily "labour only" rate - this is the rate you would need to charge to achieve your earnings target if you had no other costs as an artist;
  • calculate the daily disbursements you are likely to recharge;
  • help you work out your annual overheads as an artist, and then translate these to a day rate;
  • combine all these components into an overall day rate;
  • provide you with a document to justify that rate if challenged to do so;
  • provide an estimate for a piece of work.

In all that's an ambitious programme, but it's not as daunting as it might seem. In particular, do remember that absolute precision is not necessary in all that follows. It's quite acceptable for a figure to be a "good enough" estimate and in most cases it will do little to invalidate the outcome.

Deciding how much you want to earn

If you ask anyone how much they want to earn the almost invariable answer is "lots", or something like that. The reality is that most of us never will earn "lots" and so a sense of realism is needed about how much you actually hope to earn.

That realism has to be based on three things:

  • what other people doing the same sort of work earn;
  • what similarly qualified people in different, but not entirely dissimilar, jobs earn;
  • your own experience and flair.

The first two of these measures are reasonably objective; the third can only be assessed individually. That, however, does not mean you should dismiss its importance. It is also important for you to consult others about it, especially if you doubt what experience and flair you have, as is common amongst very many talented people. But little more can be said about it here.

As [a-n] have discovered, comparison of the rates that artist's earn is a thankless task. This makes the first option difficult. As a result the second option might well be better as the basis for assessment of what to expect to earn. There are in fact several strong and logical arguments to support this view:

  • artists have traditionally been undervalued, so to make comparison with historic payments to them might just be to continue a trend of underpayment;
  • most people who employ artists do not know an artist's worth and so will need to use other measures to help them form an opinion.

Perhaps the most obvious comparison to be made is with teachers. Again, there are strong logical reasons:

  • teachers are usually graduates, and many will have an additional qualification as well, making the training period 4 years, similar to that of many artists;
  • most teachers are employed by local authorities, and many artists will also be engaged by such authorities;
  • artists are sometimes engaged to undertake work similar to that of teachers e.g. leading workshops;
  • many of the management skills required by an artist are similar to those used by a teacher.

a-n The artists Information Company has found that at present teachers are paid the following approximate sums:

  • starting salary (outside London) £18,500;
  • average salary for an established teacher (outside London) £30,250.

An average teacher has probably had at least ten years service, after which automatic annual promotions tend to cease. Until then they are worth approximately £1,000 a year. London weighting tends to be worth not much more than £1,000 a year.

Interpreted for an artist this might mean, having rounded things to the nearest thousand pounds that:

  • a newly qualified artist, straight out of college should aim to make £19,000 a year;
  • an artist ten years out of college should hope to make £30,000 a year;
  • you should add about £1,100 a year for extra experience in between these times;
  • after you have worked for about ten years increased earnings have to be justified by personal additional experience and flair, although this option is always available at any time earlier than that if it can be justified;

if you are working in an expensive, and probably urban area, it is justified to increase your target earnings to allow for this fact by more than £1,000 a year.