You are on page 1of 7

<?

php
/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg()
function
* @return help text for the path
*/
function custom_financials_help($path, $arg) {
$doQuote=!get_magic_quotes_gpc();
$output = '';
switch ($path) {
case "admin/help#custom_financials":
$output = '<p>'. t("Financials management") .'</p>';
break;
}
return $output;
} // function custom_financials_help

function custom_financials_perm() {
return array('administer module','download files');
}

function custom_financials_menu(){
$items = array();

$items['admin/settings/custom-financials/manage-periods'] = array(
'title' => 'Custom Financials - Manage Financials (periods)',
'description' => 'Custom Financials - Manage Financials (periods)',
'page callback' => 'custom_financials_manage_periods',
'access arguments' => array('administer module'),
'type' => MENU_NORMAL_ITEM,
);

$items['admin/settings/custom-financials/manage-files'] = array(
'title' => 'Custom Financials - Manage Financials (files)',
'description' => 'Custom Financials - Manage Financials (files)',
'page callback' => 'custom_financials_manage_files',
'access arguments' => array('administer module'),
'type' => MENU_NORMAL_ITEM,
);

$items['financials-downloadfile'] = array(
'title' => 'Custom Financials - Download Files',
'description' => 'Custom Financials - Download Files',
'page callback' => 'custom_financials_download_file',
'access arguments' => array('download files'),
'type' => MENU_NORMAL_ITEM,
);

$items['financials-results'] = array(
'title' => 'Financial Results',
'description' => 'Financial Results',
'page callback' => 'custom_financials_results_frontend',
'access arguments' => array('download files'),
'type' => MENU_NORMAL_ITEM,
);
$items['financials-results-period'] = array(
'title' => 'Financial Results',
'description' => 'Financial Results (specific period)',
'page callback' => 'custom_financials_results_showfiles',
'access arguments' => array('download files'),
'type' => MENU_NORMAL_ITEM,
);

return $items;

function custom_financials_deletefile($id){
if(!user_access("administer module"))
return "In-valid operation";

$file_storage_path=customforms_getvalue("financials_files_path");
if(!$file_storage_path)
return "Please add a key 'financials_files_path' having the storage
path value in 'custom - Manage keys' module";

$query="select * from custom_financials_files where id='".$id."'";


$result=db_query($query);
if(!($record_row=$row=db_fetch_object($result)))
return "Im-proper operation";
$filename=$form_file_name=$record_row->file_name;

$query="delete from custom_financials_files


where id='".$id."'";
db_query($query);
if(db_affected_rows()==1){
unlink($file_storage_path."/".$filename);
return true;
}else{
return false;
}

function custom_financials_deletesection($id){
if(!user_access("administer module"))
return "In-valid operation";

$query="select * from custom_financials_section where id='".$id."'";


$result=db_query($query);
if(!($record_row=$row=db_fetch_object($result)))
return "Im-proper operation";

$query="select id from custom_financials_files where cfs_id='".$id."'";


$result=db_query($query);
while($row=db_fetch_object($result))
custom_financials_deletefile($row->id);

$query="delete from custom_financials_section


where id='".$id."'";
db_query($query);
if(db_affected_rows()==1){
return true;
}else{
return false;
}

function custom_financials_deletefinancial($id){
if(!user_access("administer module"))
return "In-valid operation";

$query="select * from custom_financials where id='".$id."'";


$result=db_query($query);
if(!($record_row=$row=db_fetch_object($result)))
return "Im-proper operation";

$query="select id from custom_financials_section where cf_id='".$id."'";


$result=db_query($query);
while($row=db_fetch_object($result))
custom_financials_deletesection($row->id);

$query="delete from custom_financials


where id='".$id."'";
db_query($query);
if(db_affected_rows()==1){
return true;
}else{
return false;
}

function custom_financials_manage_files(){
return include_once("manage_files.php");
}

function custom_financials_manage_periods(){
return include_once("manage_periods.php");
//return $content;
}

function custom_financials_download_file(){
$doQuote=!get_magic_quotes_gpc();
$valid=true;
$show=true;
$content="";

$file_path=customforms_getvalue("financials_files_path");

preg_match("#/([^/]*)$#",$_SERVER["REQUEST_URI"],$matches);
$file=urldecode($matches[1]);
if(!file_exists($file_path.DIRECTORY_SEPARATOR.$file)){
drupal_set_message(t('File you are trying to access does not exist
'.$file),'error');
return "";
}

$query="select * from custom_financials_files where


file_name='".trim(addslashes($file))."'";
$result=db_query($query);
if(!($row=db_fetch_object($result))){
drupal_set_message(t('This file cannot be downloaded'),'error');
return "";
}else{
if(!($row->status || user_access('administer module'))){
drupal_set_message(t('This file cannot be downloaded'),'error');
return "";
}
}

ob_clean();
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($file_path.DIRECTORY_SEPARATOR.$file));
header('Content-Disposition: attachment; filename=' . urlencode($file));
readfile($file_path.DIRECTORY_SEPARATOR.$file);
exit;
}

function custom_financials_results_frontend(){
$base_path = base_path();
$menu_string=":::About Us:::Investor Relations:::Financial Results";
$menu_href_string=":::".$base_path."aboutus:::".$base_path."investor-
relations:::aaa";
variable_set("menu_string_1",$menu_string);
variable_set("menu_href_string_1",$menu_href_string);

$doQuote=!get_magic_quotes_gpc();
$valid=true;
$show=true;
$content="";
$spacer="&nbsp;&nbsp;&nbsp;";

$module_path = drupal_get_path('module', 'custom_financials');


$directory = path_to_theme();
$images_path=$base_path.$module_path."/images";
drupal_add_css($module_path."/css/fin-styles.css");
//print "<br />".$base_path.$module_path."/css/styles.css"."<br />";

$period_year=date("Y");
$year_present=true;
if(preg_match("#/([^/]*)$#",$_SERVER["REQUEST_URI"],$matches)){
$matches[1]=urldecode($matches[1]);
if(is_numeric($matches[1]))
$period_year=$matches[1];
else
$year_present=false;
}else
$year_present=false;

if(!$year_present){
$query="select max(period_year) as max_year from custom_financials
where status='1'";
$resultset=db_query($query);
if($row=db_fetch_object($resultset))
$period_year=$row->max_year;
}
$inner_content="";
$query="select * from custom_financials where period_year='".$period_year."'
and status='1' order by sortindex desc, period_text1";
$resultset=db_query($query);
while($row=db_fetch_object($resultset))
$inner_content.="<tr><td><img src=\"".$images_path."/dot.gif\"
align=\"texttop\" height=\"6px\" width=\"6px\" />".$spacer."<a class=\"greenlink\"
href=\"".$base_path."financials-results-period/".$row->id."\">".$row-
>period_text1."</a><br /><br /></td></tr>";
if(strlen($inner_content)>0){
$content.="<div class=\"headboldgreen\" style=\"margin-
bottom:10px;\">".$period_year."</div>";
$content.="<table>".$inner_content."</table>";
}

return $content;

function custom_financials_results_showfiles(){
$base_path = base_path();
$menu_string=":::About Us:::Investor Relations:::Financial Results";
$menu_href_string=":::".$base_path."aboutus:::".$base_path."investor-
relations:::aaa";
variable_set("menu_string_1",$menu_string);
variable_set("menu_href_string_1",$menu_href_string);

$doQuote=!get_magic_quotes_gpc();
$valid=true;
$show=true;
$content="";
$spacer="&nbsp;&nbsp;&nbsp;";

$module_path = drupal_get_path('module', 'custom_financials');

$directory = path_to_theme();
$images_path=$base_path.$module_path."/images";
drupal_add_css($module_path."/css/fin-styles.css");
//print "<br />".$base_path.$module_path."/css/styles.css"."<br />";

$id=0;
if(preg_match("#/([^/]*)$#",$_SERVER["REQUEST_URI"],$matches)){
$matches[1]=urldecode($matches[1]);
if(is_numeric($matches[1]))
$id=$matches[1];
else
return "Please enter a proper period";
}else
return "Please enter a proper period";

//build query 1 starts


$query="
SELECT custom_financials_files.heading, custom_financials_files.file_name,
custom_financials_section.id as section_id, custom_financials.period_year
FROM custom_financials_files,custom_financials_section,custom_financials
WHERE custom_financials_files.cfs_id=custom_financials_section.id and
custom_financials_files.status=1 and
custom_financials_section.cf_id=custom_financials.id and
custom_financials.id='".$id."' and custom_financials.status=1
order by custom_financials_section.sortindex desc, custom_financials_section.id";
//build query 1 ends

//print $query;exit;

$files_array=array();
$resultset=db_query($query);
while($row=db_fetch_array($resultset))
$files_array[]=$row;

if(count($files_array)==0)
return "No records were found";

//build query 2 starts


$query="
SELECT custom_financials_section.body as section_body,
custom_financials_section.id as section_id, custom_financials.period_year
FROM custom_financials_section,custom_financials
WHERE custom_financials_section.cf_id=custom_financials.id and
custom_financials.id='".$id."' and custom_financials.status=1
order by custom_financials_section.sortindex desc, custom_financials_section.id";
//build query 2 ends

//print $query;exit;

$sections_array=array();
$resultset=db_query($query);
while($row=db_fetch_array($resultset))
$sections_array[]=$row;

$j=0;
$period_year=$sections_array[0]["period_year"];
for($i=0;$i<count($sections_array);$i++){
if($i==0 || $period_year!=$sections_array[$i]["period_year"])
$content.="<div class=\"headboldgreen\" style=\"margin-
bottom:10px;\">".$sections_array[$i]["period_year"]."</div>";
$content.="<div class=\"conttable1\" style=\"margin-
bottom:10px;\">".$sections_array[$i]["section_body"]."</div>";
$content.="<div style=\"margin-bottom:15px\">";
for(;$j<count($files_array) &&
$files_array[$j]["section_id"]==$sections_array[$i]["section_id"];$j++)
$content.="<img src=\"".$images_path."/dot.gif\"
align=\"absmiddle\" height=\"6px\" width=\"6px\" style=\"padding-bottom:2px;\"
/>".$spacer."<a class=\"greenlink\" href=\"".$base_path."financials-
downloadfile/".$files_array[$j]["file_name"]."\">".$files_array[$j]["heading"]."</
a><br />";
$content.="</div>";
}
return $content;
}

function custom_financials_block($op='list', $delta=0) {


$doQuote=!get_magic_quotes_gpc();
$website_name=variable_get("website_name","sifycorp");
$base_path = base_path();
$directory = drupal_get_path('module', 'newupload');
$content="";

$block['subject'] = '';
$block['content'] = '';

// listing of blocks, such as on the admin/block page


if ($op == "list") {
$block[0]["info"] = t('Custom Financials Module - Show on right side');
}
if ($op == 'view') {
switch($delta){
case 0:
$block['subject'] = '';
$block['content'] = '';
if(user_access('download files')){
$periods_array=array();
$query="select * from custom_financials where status='1'
order by period_year desc, sortindex desc, period_text2";
$resultset=db_query($query);
while($row=db_fetch_array($resultset))
$periods_array[]=$row;

$period_year=date("Y");
if(count($periods_array)>0){
for($i=0;$i<count($periods_array);$i++){
$period_year=$periods_array[$i]["period_year"];
if($i==0 || $period_year!=$periods_array[$i-
1]["period_year"]){
$content.="<div class=\"headboldgreen\"
style=\"margin-bottom:10px;\">".$periods_array[$i]["period_year"]."</div>
<div class=\"year_financial\"
style=\"margin-bottom:10px;\">
";

}
$content.="<img
src=\"".$images_path."/dot.gif\" align=\"absmiddle\" height=\"6px\" width=\"6px\"
style=\"padding-bottom:2px;\" />".$spacer."<a class=\"rightnavbottomlink\"
href=\"".$base_path."financials-results-
period/".$periods_array[$i]["id"]."\">".$periods_array[$i]["period_text2"]."</a><b
r />";

if($period_year!=$periods_array[$i+1]["period_year"])
$content.="</div>";
}
}
$block["content"]=$content;
}
break;
}
}
return $block;
}

You might also like