/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
1
<?php
2
3
 
4
//   $res = exec('ps xa | grep "downloads_check.php" | grep -v grep | wc -l');
5
//   if ($res > 1) exit;
6
7
  if (preg_match("/(.*)downloads_check.php$/", $_SERVER['SCRIPT_FILENAME'], $m)) @chdir($m[1]);
8
  require("../adei.php"); 
9
10
  $lock = new LOCK("downloads_check");
11
  $lock->Lock(LOCK::BLOCK);
12
13
  global $ADEI;
14
  global $ADEI_ROOTDIR;
368 by Artur Reymers
Add: Support of local setup view and views
15
  $ADEI->RequireClass("download");
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
16
17
  $cache = new CACHEDB();
18
  $dm = new DOWNLOADMANAGER(); 
368 by Artur Reymers
Add: Support of local setup view and views
19
  $res = $cache->GetDownloads("","ASC");
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
20
21
  while($row = mysql_fetch_array($res)) {
216 by Suren A. Chilingaryan
Quick fix (not a real one) of the system scripts belonging to download manager
22
    $download = $row['dl_id'];
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
23
    $status = $row['status'];
24
    $name = $dm->Getfilename($download); 
25
    $file = $ADEI_ROOTDIR."tmp/downloads/".$name;
216 by Suren A. Chilingaryan
Quick fix (not a real one) of the system scripts belonging to download manager
26
    if (file_exists($file)) {
368 by Artur Reymers
Add: Support of local setup view and views
27
	$fsize = filesize($file);
216 by Suren A. Chilingaryan
Quick fix (not a real one) of the system scripts belonging to download manager
28
	$lastmodified = time() - filemtime($file);
29
    } else {
30
	$fsize = 0;
31
	$lastmodified = 0;
32
    }
33
    if($fsize > 1 && $lastmodified > 1 && $status != 'Ready') {
34
	    // We should check if it's really complete (I think - not), and remove failed downloads
35
	    // We also should check that it is not in progress (old mtime?)
36
	//$dm->ChangeStatus($row['dl_id'], 'Ready');
37
    }
38
    if ($status == "Preparing" || $status == "Finalizing") {
39
	// We should check if something just failed
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
40
      $busy = 1;
41
    }
42
    if($nextdownload == "" && $status == "Queue"){
43
      $nextdownload = $row['dl_id'];	
44
    }
368 by Artur Reymers
Add: Support of local setup view and views
45
  }
46
47
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
48
  if($nextdownload != "" && $busy != 1) {
49
    try {
50
      $opts = $dm->CreateDataRequestOpts($nextdownload); 
51
      $dm->DataRequest($opts);
368 by Artur Reymers
Add: Support of local setup view and views
52
    } catch(ADEIException $ex) {
53
      //$dm->Logit($ex->getMessage());
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
54
      $dm->ChangeStatus($nextdownload, "ERROR");
368 by Artur Reymers
Add: Support of local setup view and views
55
      $dm->SetError($nextdownload, $ex->getMessage());
210.1.2 by Suren A. Chilingaryan
Download manager by Aki Rimpelainen
56
    }
57
  }
58
59
  $lock->UnLock();
60
  unset($lock);
61
62
?>